From 96cdf91c3c4e052b0cd7976b32661c174a426c79 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 30 Nov 2019 22:31:34 +0100 Subject: [PATCH] Use pcov to speed up tests with code coverage --- .gitlab-ci.yml | 4 ++-- README.md | 5 +++++ docker/dev/Dockerfile | 4 ++-- src/Http/SessionServiceProvider.php | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82c9fd6d..c7ff2229 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/README.md b/README.md index 6333d245..8f1cb705 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index ef514102..98fb3177 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -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,\ diff --git a/src/Http/SessionServiceProvider.php b/src/Http/SessionServiceProvider.php index 4d779aa6..d187b439 100644 --- a/src/Http/SessionServiceProvider.php +++ b/src/Http/SessionServiceProvider.php @@ -74,6 +74,6 @@ class SessionServiceProvider extends ServiceProvider */ protected function isCli() { - return PHP_SAPI == 'cli'; + return PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg'; } }