Use pcov to speed up tests with code coverage

This commit is contained in:
Igor Scheller 2019-11-30 22:31:34 +01:00
parent 9329889235
commit 96cdf91c3c
4 changed files with 10 additions and 5 deletions

View File

@ -67,7 +67,7 @@ test:
junit: ./unittests.xml
coverage: '/^\s*Lines:\s*(\d+(?:\.\d+)?%)/'
before_script:
- apk add ${PHPIZE_DEPS} && pecl install xdebug && docker-php-ext-enable xdebug
- apk add -q ${PHPIZE_DEPS} && pecl install pcov > /dev/null && docker-php-ext-enable pcov
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
- cp -R tests/ phpunit.xml "${DOCROOT}"
- HOMEDIR=$PWD
@ -75,7 +75,7 @@ test:
- composer --no-ansi install
- ./bin/migrate
script:
- ./vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- php -d pcov.enabled=1 vendor/bin/phpunit -vvv --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- ./bin/migrate down
check-style:

View File

@ -101,6 +101,11 @@ vendor/bin/phpunit --testsuite Feature
vendor/bin/phpunit
```
To run code coverage reports its highly recommended to use [`pcov`](https://github.com/krakjoe/pcov) or at least `phpdbg -qrr`(which has problems with switch case statements) as using Xdebug slows down execution.
```bash
php -d pcov.enabled=1 vendor/bin/phpunit --testsuite Unit --coverage-text
```
### CI & Build Pipeline
The engelsystem can be tested and automatically deployed to a testing/staging/production environment.
This functionality requires a [GitLab](https://about.gitlab.com/) server with a working docker runner.

View File

@ -2,9 +2,9 @@
FROM php:7-fpm-alpine AS es_php_fpm
WORKDIR /var/www
RUN apk add --no-cache icu-dev $PHPIZE_DEPS && \
pecl install xdebug && \
pecl install pcov xdebug && \
docker-php-ext-install intl pdo_mysql && \
docker-php-ext-enable xdebug
docker-php-ext-enable pcov xdebug
RUN echo -e "xdebug.remote_enable=1\nxdebug.remote_connect_back=1\n" >> /usr/local/etc/php/conf.d/xdebug.ini
ENV TRUSTED_PROXIES 10.0.0.0/8,::ffff:10.0.0.0/8,\

View File

@ -74,6 +74,6 @@ class SessionServiceProvider extends ServiceProvider
*/
protected function isCli()
{
return PHP_SAPI == 'cli';
return PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg';
}
}