diff --git a/src/Console/Application.php b/src/Console/Application.php index 5059e8610..6f1d3ec17 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -188,6 +188,8 @@ private function logRunningWithDebugger(): void $this->consoleOutput->logRunningWithDebugger(\PHP_SAPI); } elseif (\extension_loaded('xdebug')) { $this->consoleOutput->logRunningWithDebugger('Xdebug'); + } elseif (\extension_loaded('pcov')) { + $this->consoleOutput->logRunningWithDebugger('PCOV'); } } } diff --git a/src/Process/Coverage/CoverageRequirementChecker.php b/src/Process/Coverage/CoverageRequirementChecker.php index 8f0e21287..5eb6978cb 100644 --- a/src/Process/Coverage/CoverageRequirementChecker.php +++ b/src/Process/Coverage/CoverageRequirementChecker.php @@ -63,6 +63,7 @@ public function hasDebuggerOrCoverageOption(): bool return $this->skipCoverage || \PHP_SAPI === 'phpdbg' || \extension_loaded('xdebug') + || \extension_loaded('pcov') || XdebugHandler::getSkippedVersion() || $this->isXdebugIncludedInInitialTestPhpOptions(); } diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/README.md b/tests/Fixtures/e2e/PCOV_PHPUnit8/README.md new file mode 100644 index 000000000..5042b9fdc --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/README.md @@ -0,0 +1,8 @@ +# Test Infection with PCOV and PHPUnit 8 + +https://github.com/infection/infection/issues/665 + +## Summary + +...the issue boils down to Infection not being aware of PCOV as a coverage driver. + diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/composer.json b/tests/Fixtures/e2e/PCOV_PHPUnit8/composer.json new file mode 100644 index 000000000..b19c83a95 --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/composer.json @@ -0,0 +1,15 @@ +{ + "require-dev": { + "phpunit/phpunit": "^8" + }, + "autoload": { + "psr-4": { + "PCOV_PHPUnit8\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "PCOV_PHPUnit8\\Test\\": "tests/" + } + } +} diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/expected-output.txt b/tests/Fixtures/e2e/PCOV_PHPUnit8/expected-output.txt new file mode 100644 index 000000000..99606b97d --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/expected-output.txt @@ -0,0 +1,6 @@ +Total: 1 +Killed: 1 +Errored: 0 +Escaped: 0 +Timed Out: 0 +Not Covered: 0 \ No newline at end of file diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/infection.json b/tests/Fixtures/e2e/PCOV_PHPUnit8/infection.json new file mode 100644 index 000000000..7029746fb --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/infection.json @@ -0,0 +1,12 @@ +{ + "timeout": 25, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "summary": "infection.log" + }, + "tmpDir": "." +} diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/phpunit.xml.dist b/tests/Fixtures/e2e/PCOV_PHPUnit8/phpunit.xml.dist new file mode 100644 index 000000000..9a836774d --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + + + + ./src/ + + + diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/run_tests.bash b/tests/Fixtures/e2e/PCOV_PHPUnit8/run_tests.bash new file mode 100755 index 000000000..d0d2c1c0b --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/run_tests.bash @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -e + +tputx () { + test -x $(which tput) && tput "$@" +} + +run () { + local INFECTION=${1} + local PHPARGS=${2} + + if [ "$PHPDBG" = "1" ] + then + phpdbg $PHPARGS -qrr $INFECTION + else + php $PHPARGS $INFECTION + fi +} + +cd $(dirname "$0") + +if [ "$PHPDBG" = "1" ] +then + exit 0 +fi + +if php -r "exit(version_compare(PHP_VERSION, '7.3.0'));" +then + exit 0 +fi + +tputx bold +echo "Checking for PCOV..." +tputx sgr0 + + +if ! php --ri pcov +then + tput setaf 1 # red + echo "PCOV not detected" + exit 0 +fi + +readonly INFECTION=../../../../${1} + +set -e pipefail + +php $INFECTION + +diff -w expected-output.txt infection.log + diff --git a/tests/Fixtures/e2e/PCOV_PHPUnit8/src/SourceClass.php b/tests/Fixtures/e2e/PCOV_PHPUnit8/src/SourceClass.php new file mode 100644 index 000000000..24dbe38d9 --- /dev/null +++ b/tests/Fixtures/e2e/PCOV_PHPUnit8/src/SourceClass.php @@ -0,0 +1,11 @@ +assertSame('hello', $sourceClass->hello()); + } +}