diff --git a/src/PatchCoverage.php b/src/PatchCoverage.php index 43181c5..8789c33 100644 --- a/src/PatchCoverage.php +++ b/src/PatchCoverage.php @@ -25,6 +25,7 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre $result = [ 'numChangedLinesThatAreExecutable' => 0, 'numChangedLinesThatWereExecuted' => 0, + 'numChangedLinesNotCovered' => 0, 'changedLinesThatWereNotExecuted' => [], ]; @@ -77,6 +78,9 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre $result['numChangedLinesThatWereExecuted']++; } } + if (isset($coverage[$key]) && !isset($coverage[$key][$line])) { + $result['numChangedLinesNotCovered']++; + } } } diff --git a/src/cli/PatchCoverageCommand.php b/src/cli/PatchCoverageCommand.php index 5fcaf8e..e016289 100644 --- a/src/cli/PatchCoverageCommand.php +++ b/src/cli/PatchCoverageCommand.php @@ -44,7 +44,8 @@ public function run(Arguments $arguments): int ); if ($patchCoverage['numChangedLinesThatWereExecuted'] === 0 && - $patchCoverage['numChangedLinesThatAreExecutable'] === 0) { + $patchCoverage['numChangedLinesThatAreExecutable'] === 0 && + $patchCoverage['numChangedLinesNotCovered'] === 0) { print 'Unable to detect executable lines that were changed.' . PHP_EOL; if ($pathPrefix === '') { diff --git a/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt new file mode 100644 index 0000000..9a75c72 --- /dev/null +++ b/tests/end-to-end/patch-coverage/no-errors-with-only-not-covered-changed-lines.phpt @@ -0,0 +1,20 @@ +--TEST-- +phpcov patch-coverage --path-prefix /path/prefix ../../fixture/example2/coverage/testGreetsWorld2.cov ../../fixture/example2/patch2 +--INI-- +xdebug.overload_var_dump=0 +--FILE-- +run($_SERVER['argv'])); +--EXPECTF-- +phpcov %s by Sebastian Bergmann. + +0 / 0 changed executable lines covered () +int(0) diff --git a/tests/fixture/example2/coverage/testGreetsWorld2.cov b/tests/fixture/example2/coverage/testGreetsWorld2.cov new file mode 100644 index 0000000..67ebef4 Binary files /dev/null and b/tests/fixture/example2/coverage/testGreetsWorld2.cov differ diff --git a/tests/fixture/example2/patch2 b/tests/fixture/example2/patch2 new file mode 100644 index 0000000..97d73c2 --- /dev/null +++ b/tests/fixture/example2/patch2 @@ -0,0 +1,13 @@ +diff --git a/tests/fixture/example2/src/Greeter2.php b/tests/fixture/example2/src/Greeter2.php +index 36e0a2e..ab7b878 100644 +--- a/tests/fixture/example2/src/Greeter2.php ++++ b/tests/fixture/example2/src/Greeter2.php +@@ -4,7 +4,7 @@ + + final class Greeter2 + { +- public const GREETING='Hello world!'; ++ public const GREETING='Hello wonderful world!'; + + public function greetWorld(): string + { diff --git a/tests/fixture/example2/phpunit.xml b/tests/fixture/example2/phpunit.xml new file mode 100644 index 0000000..c1f86c8 --- /dev/null +++ b/tests/fixture/example2/phpunit.xml @@ -0,0 +1,18 @@ + + + + + tests + + + + + + src + + + diff --git a/tests/fixture/example2/src/Greeter2.php b/tests/fixture/example2/src/Greeter2.php new file mode 100644 index 0000000..36e0a2e --- /dev/null +++ b/tests/fixture/example2/src/Greeter2.php @@ -0,0 +1,13 @@ +assertSame(Greeter2::GREETING, (new Greeter2())->greetWorld()); + } +}