diff --git a/.travis.yml b/.travis.yml index 980fe7fbf..6f42a3db2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,22 +17,39 @@ env: matrix: - DRIVER="xdebug" DEPENDENCIES="high" - DRIVER="phpdbg" DEPENDENCIES="high" + - DRIVER="pcov" DEPENDENCIES="high" - DRIVER="xdebug" DEPENDENCIES="low" - DRIVER="phpdbg" DEPENDENCIES="low" + - DRIVER="pcov" DEPENDENCIES="low" global: - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" before_install: - composer self-update - composer clear-cache + - export COMPOSER_ROOT_VERSION=6.1.99 install: - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi +before_script: + - | + if [[ "$DRIVER" = 'pcov' ]]; then + echo > $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini + git clone https://github.com/krakjoe/pcov + cd pcov + phpize + ./configure + make clean install + echo "extension=pcov.so" > $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/pcov.ini + cd $TRAVIS_BUILD_DIR + fi + script: - if [[ "$DRIVER" = 'phpdbg' ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - if [[ "$DRIVER" = 'xdebug' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi + - if [[ "$DRIVER" = 'pcov' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index 0d419a5b0..3008f4016 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "phpunit/php-token-stream": "^3.0.1", "phpunit/php-text-template": "^1.2.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.0", + "sebastian/environment": "^4.1", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, @@ -57,5 +57,6 @@ "branch-alias": { "dev-master": "6.1-dev" } - } + }, + "minimum-stability": "dev" } diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 67ba40359..69b4bc00a 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -14,6 +14,7 @@ use PHPUnit\Util\Test; use SebastianBergmann\CodeCoverage\Driver\Driver; use SebastianBergmann\CodeCoverage\Driver\PHPDBG; +use SebastianBergmann\CodeCoverage\Driver\PCOV; use SebastianBergmann\CodeCoverage\Driver\Xdebug; use SebastianBergmann\CodeCoverage\Node\Builder; use SebastianBergmann\CodeCoverage\Node\Directory; @@ -905,6 +906,10 @@ private function selectDriver(Filter $filter): Driver return new Xdebug($filter); } + if ($runtime->hasPCOV()) { + return new PCOV($filter); + } + throw new RuntimeException('No code coverage driver available'); } diff --git a/src/Driver/PCOV.php b/src/Driver/PCOV.php new file mode 100644 index 000000000..941650e23 --- /dev/null +++ b/src/Driver/PCOV.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\CodeCoverage\Driver; + +use SebastianBergmann\CodeCoverage\RuntimeException; +use SebastianBergmann\CodeCoverage\Filter; + +/** + * Driver for PCOV code coverage functionality. + * + * @codeCoverageIgnore + */ +final class PCOV implements Driver +{ + public function __construct(Filter $filter = null) + { + + } + + /** + * Start collection of code coverage information. + */ + public function start(bool $determineUnusedAndDead = true): void + { + \pcov\start(); + } + + /** + * Stop collection of code coverage information. + */ + public function stop(): array + { + \pcov\stop(); + + $waiting = \pcov\waiting(); + $collect = []; + + if ($waiting) { + $collect = \pcov\collect(\pcov\inclusive, $waiting); + + if ($collect) { + \pcov\clear(); + } + } + + return $collect; + } +} diff --git a/tests/tests/CodeCoverageTest.php b/tests/tests/CodeCoverageTest.php index c1a52b89f..a3f2baf49 100644 --- a/tests/tests/CodeCoverageTest.php +++ b/tests/tests/CodeCoverageTest.php @@ -11,6 +11,7 @@ use SebastianBergmann\CodeCoverage\Driver\Driver; use SebastianBergmann\CodeCoverage\Driver\PHPDBG; +use SebastianBergmann\CodeCoverage\Driver\PCOV; use SebastianBergmann\CodeCoverage\Driver\Xdebug; use SebastianBergmann\Environment\Runtime;