diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 6445c6d27..992d6c92c 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -256,6 +256,8 @@ public function append(RawCodeCoverageData $rawData, $id = null, bool $append = $this->applyFilter($rawData); + $this->applyExecutableLinesFilter($rawData); + if ($this->useAnnotationsForIgnoringCode) { $this->applyIgnoredLinesFilter($rawData); } @@ -466,7 +468,8 @@ private function applyCoversAnnotationFilter(RawCodeCoverageData $rawData, $line if (is_array($linesToBeCovered)) { foreach ($linesToBeCovered as $fileToBeCovered => $includedLines) { - $rawData->keepCoverageDataOnlyForLines($fileToBeCovered, $includedLines); + $rawData->keepLineCoverageDataOnlyForLines($fileToBeCovered, $includedLines); + $rawData->keepFunctionCoverageDataOnlyForLines($fileToBeCovered, $includedLines); } } } @@ -484,6 +487,16 @@ private function applyFilter(RawCodeCoverageData $data): void } } + private function applyExecutableLinesFilter(RawCodeCoverageData $data): void + { + foreach (array_keys($data->lineCoverage()) as $filename) { + $data->keepLineCoverageDataOnlyForLines( + $filename, + $this->uncoveredFileAnalyser()->executableLinesIn($filename) + ); + } + } + private function applyIgnoredLinesFilter(RawCodeCoverageData $data): void { foreach (array_keys($data->lineCoverage()) as $filename) { diff --git a/src/RawCodeCoverageData.php b/src/RawCodeCoverageData.php index ae5044ffe..606bd773f 100644 --- a/src/RawCodeCoverageData.php +++ b/src/RawCodeCoverageData.php @@ -126,7 +126,7 @@ public function removeCoverageDataForFile(string $filename): void /** * @param int[] $lines */ - public function keepCoverageDataOnlyForLines(string $filename, array $lines): void + public function keepLineCoverageDataOnlyForLines(string $filename, array $lines): void { if (!isset($this->lineCoverage[$filename])) { return; @@ -136,17 +136,25 @@ public function keepCoverageDataOnlyForLines(string $filename, array $lines): vo $this->lineCoverage[$filename], array_flip($lines) ); + } - if (isset($this->functionCoverage[$filename])) { - foreach ($this->functionCoverage[$filename] as $functionName => $functionData) { - foreach ($functionData['branches'] as $branchId => $branch) { - if (count(array_diff(range($branch['line_start'], $branch['line_end']), $lines)) > 0) { - unset($this->functionCoverage[$filename][$functionName]['branches'][$branchId]); + /** + * @param int[] $lines + */ + public function keepFunctionCoverageDataOnlyForLines(string $filename, array $lines): void + { + if (!isset($this->functionCoverage[$filename])) { + return; + } - foreach ($functionData['paths'] as $pathId => $path) { - if (in_array($branchId, $path['path'], true)) { - unset($this->functionCoverage[$filename][$functionName]['paths'][$pathId]); - } + foreach ($this->functionCoverage[$filename] as $functionName => $functionData) { + foreach ($functionData['branches'] as $branchId => $branch) { + if (count(array_diff(range($branch['line_start'], $branch['line_end']), $lines)) > 0) { + unset($this->functionCoverage[$filename][$functionName]['branches'][$branchId]); + + foreach ($functionData['paths'] as $pathId => $path) { + if (in_array($branchId, $path['path'], true)) { + unset($this->functionCoverage[$filename][$functionName]['paths'][$pathId]); } } } diff --git a/src/StaticAnalysis/CachingUncoveredFileAnalyser.php b/src/StaticAnalysis/CachingUncoveredFileAnalyser.php index f52bb3518..046004954 100644 --- a/src/StaticAnalysis/CachingUncoveredFileAnalyser.php +++ b/src/StaticAnalysis/CachingUncoveredFileAnalyser.php @@ -28,13 +28,15 @@ public function __construct(string $directory, UncoveredFileAnalyser $uncoveredF public function executableLinesIn(string $filename): array { - if ($this->has($filename, __METHOD__)) { - return $this->read($filename, __METHOD__); + $cacheKey = 'v2' . __METHOD__; + + if ($this->has($filename, $cacheKey)) { + return $this->read($filename, $cacheKey); } $data = $this->uncoveredFileAnalyser->executableLinesIn($filename); - $this->write($filename, __METHOD__, $data); + $this->write($filename, $cacheKey, $data); return $data; } diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index 32205692d..2121466bc 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -9,9 +9,10 @@ */ namespace SebastianBergmann\CodeCoverage\StaticAnalysis; -use function array_unique; -use function sort; use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp; +use PhpParser\Node\Expr\CallLike; +use PhpParser\Node\Scalar; use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Case_; use PhpParser\Node\Stmt\Catch_; @@ -26,6 +27,7 @@ use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Goto_; use PhpParser\Node\Stmt\If_; +use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\Throw_; @@ -40,34 +42,69 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract { /** - * @psalm-var list + * @psalm-var array */ private $executableLines = []; + /** + * @psalm-var array + */ + private $propertyLines = []; + public function enterNode(Node $node): void { + $this->savePropertyLines($node); + if (!$this->isExecutable($node)) { return; } - $this->executableLines[] = $node->getStartLine(); + $line = $this->getLine($node); + + if (isset($this->propertyLines[$line])) { + return; + } + + $this->executableLines[$line] = $line; } /** - * @psalm-return list + * @psalm-return array */ public function executableLines(): array { - $executableLines = array_unique($this->executableLines); + return $this->executableLines; + } + + private function savePropertyLines(Node $node): void + { + if (!$node instanceof Property && !$node instanceof Node\Stmt\ClassConst) { + return; + } - sort($executableLines); + foreach (range($node->getStartLine(), $node->getEndLine()) as $index) { + $this->propertyLines[$index] = $index; + } + } + + private function getLine(Node $node): int + { + if ( + $node instanceof Node\Expr\PropertyFetch || + $node instanceof Node\Expr\NullsafePropertyFetch || + $node instanceof Node\Expr\StaticPropertyFetch + ) { + return $node->getEndLine(); + } - return $executableLines; + return $node->getStartLine(); } private function isExecutable(Node $node): bool { - return $node instanceof Break_ || + return $node instanceof BinaryOp || + $node instanceof Break_ || + $node instanceof CallLike || $node instanceof Case_ || $node instanceof Catch_ || $node instanceof Continue_ || @@ -82,10 +119,15 @@ private function isExecutable(Node $node): bool $node instanceof Goto_ || $node instanceof If_ || $node instanceof Return_ || + $node instanceof Scalar || $node instanceof Switch_ || $node instanceof Throw_ || $node instanceof TryCatch || $node instanceof Unset_ || + $node instanceof Node\Expr\Assign || + $node instanceof Node\Expr\PropertyFetch || + $node instanceof Node\Expr\NullsafePropertyFetch || + $node instanceof Node\Expr\StaticPropertyFetch || $node instanceof While_; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index aa2b010c5..905c3c53e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,6 +45,8 @@ protected function getLineCoverageXdebugDataForBankAccount() 29 => -1, 31 => -1, 32 => -2, + 33 => -2, + 35 => 1, ], ]), RawCodeCoverageData::fromXdebugWithoutPathCoverage([ @@ -59,6 +61,7 @@ protected function getLineCoverageXdebugDataForBankAccount() 29 => 1, 31 => -1, 32 => -2, + 33 => -2, ], ]), RawCodeCoverageData::fromXdebugWithoutPathCoverage([ @@ -90,6 +93,7 @@ protected function getLineCoverageXdebugDataForBankAccount() 29 => 1, 31 => 1, 32 => -2, + 33 => -2, ], ]), ]; @@ -1346,12 +1350,10 @@ protected function getExpectedLineCoverageDataArrayForBankAccount(): array 0 => 'BankAccountTest::testBalanceIsInitiallyZero', 1 => 'BankAccountTest::testDepositWithdrawMoney', ], - 9 => null, 13 => [], 14 => [], 15 => [], 16 => [], - 18 => [], 22 => [ 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2', 1 => 'BankAccountTest::testDepositWithdrawMoney', @@ -1359,7 +1361,6 @@ protected function getExpectedLineCoverageDataArrayForBankAccount(): array 24 => [ 0 => 'BankAccountTest::testDepositWithdrawMoney', ], - 25 => null, 29 => [ 0 => 'BankAccountTest::testBalanceCannotBecomeNegative', 1 => 'BankAccountTest::testDepositWithdrawMoney', @@ -1380,12 +1381,10 @@ protected function getExpectedLineCoverageDataArrayForBankAccountInReverseOrder( 0 => 'BankAccountTest::testDepositWithdrawMoney', 1 => 'BankAccountTest::testBalanceIsInitiallyZero', ], - 9 => null, 13 => [], 14 => [], 15 => [], 16 => [], - 18 => [], 22 => [ 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2', 1 => 'BankAccountTest::testDepositWithdrawMoney', @@ -1393,7 +1392,6 @@ protected function getExpectedLineCoverageDataArrayForBankAccountInReverseOrder( 24 => [ 0 => 'BankAccountTest::testDepositWithdrawMoney', ], - 25 => null, 29 => [ 0 => 'BankAccountTest::testDepositWithdrawMoney', 1 => 'BankAccountTest::testBalanceCannotBecomeNegative', diff --git a/tests/_files/BankAccount-clover-line.xml b/tests/_files/BankAccount-clover-line.xml index 2f11d819c..07afc5b8c 100644 --- a/tests/_files/BankAccount-clover-line.xml +++ b/tests/_files/BankAccount-clover-line.xml @@ -3,7 +3,7 @@ - + @@ -12,15 +12,14 @@ - - + - + diff --git a/tests/_files/BankAccount-clover-path.xml b/tests/_files/BankAccount-clover-path.xml index fe7cfe602..b441efcfc 100644 --- a/tests/_files/BankAccount-clover-path.xml +++ b/tests/_files/BankAccount-clover-path.xml @@ -3,7 +3,7 @@ - + @@ -12,15 +12,14 @@ - - + - + diff --git a/tests/_files/BankAccount-cobertura-line.xml b/tests/_files/BankAccount-cobertura-line.xml index 702544c31..665760058 100644 --- a/tests/_files/BankAccount-cobertura-line.xml +++ b/tests/_files/BankAccount-cobertura-line.xml @@ -1,13 +1,13 @@ - + %s - + - + @@ -20,7 +20,6 @@ - @@ -42,7 +41,6 @@ - diff --git a/tests/_files/BankAccount-cobertura-path.xml b/tests/_files/BankAccount-cobertura-path.xml index 9f8ac5e37..b57c03148 100644 --- a/tests/_files/BankAccount-cobertura-path.xml +++ b/tests/_files/BankAccount-cobertura-path.xml @@ -1,13 +1,13 @@ - + %s - + - + @@ -20,7 +20,6 @@ - @@ -42,7 +41,6 @@ - diff --git a/tests/_files/BankAccount-text-line.txt b/tests/_files/BankAccount-text-line.txt index 892d83464..133c73797 100644 --- a/tests/_files/BankAccount-text-line.txt +++ b/tests/_files/BankAccount-text-line.txt @@ -1,12 +1,12 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 50.00% (5/10) + + Summary: + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 55.56% (5/9) BankAccount - Methods: 75.00% ( 3/ 4) Lines: 50.00% ( 5/ 10) + Methods: 75.00% ( 3/ 4) Lines: 55.56% ( 5/ 9) diff --git a/tests/_files/BankAccount-text-path.txt b/tests/_files/BankAccount-text-path.txt index d39487148..653f9ffed 100644 --- a/tests/_files/BankAccount-text-path.txt +++ b/tests/_files/BankAccount-text-path.txt @@ -1,14 +1,14 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Paths: 60.00% (3/5) + + Summary: + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Paths: 60.00% (3/5) Branches: 42.86% (3/7) - Lines: 50.00% (5/10) + Lines: 55.56% (5/9) BankAccount - Methods: 75.00% ( 3/ 4) Paths: 60.00% ( 3/ 5) Branches: 42.86% ( 3/ 7) Lines: 50.00% ( 5/ 10) + Methods: 75.00% ( 3/ 4) Paths: 60.00% ( 3/ 5) Branches: 42.86% ( 3/ 7) Lines: 55.56% ( 5/ 9) diff --git a/tests/_files/BankAccount-text-summary.txt b/tests/_files/BankAccount-text-summary.txt index c0fb9cc7d..96390c4cd 100644 --- a/tests/_files/BankAccount-text-summary.txt +++ b/tests/_files/BankAccount-text-summary.txt @@ -3,5 +3,5 @@ Code Coverage Report Summary: Classes: 0.00% (0/1) Methods: 75.00% (3/4) - Lines: 50.00% (5/10) + Lines: 55.56% (5/9) diff --git a/tests/_files/BankAccount.php b/tests/_files/BankAccount.php index 4238c1559..70f4ed78e 100644 --- a/tests/_files/BankAccount.php +++ b/tests/_files/BankAccount.php @@ -29,5 +29,6 @@ public function withdrawMoney($balance) $this->setBalance($this->getBalance() - $balance); return $this->getBalance(); + return $this->getBalance(); } } diff --git a/tests/_files/BankAccountWithUncovered-text-line.txt b/tests/_files/BankAccountWithUncovered-text-line.txt index c80e703db..4193b5ec7 100644 --- a/tests/_files/BankAccountWithUncovered-text-line.txt +++ b/tests/_files/BankAccountWithUncovered-text-line.txt @@ -6,7 +6,7 @@ Code Coverage Report: Summary: Classes: 0.00% (0/2) Methods: 37.50% (3/8) - Lines: 26.32% (5/19) + Lines: 27.78% (5/18) BankAccount - Methods: 75.00% ( 3/ 4) Lines: 50.00% ( 5/ 10) + Methods: 75.00% ( 3/ 4) Lines: 55.56% ( 5/ 9) diff --git a/tests/_files/BankAccountWithoutUncovered-text-line.txt b/tests/_files/BankAccountWithoutUncovered-text-line.txt index 892d83464..133c73797 100644 --- a/tests/_files/BankAccountWithoutUncovered-text-line.txt +++ b/tests/_files/BankAccountWithoutUncovered-text-line.txt @@ -1,12 +1,12 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 50.00% (5/10) + + Summary: + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 55.56% (5/9) BankAccount - Methods: 75.00% ( 3/ 4) Lines: 50.00% ( 5/ 10) + Methods: 75.00% ( 3/ 4) Lines: 55.56% ( 5/ 9) diff --git a/tests/_files/NamespacedBankAccount-text.txt b/tests/_files/NamespacedBankAccount-text.txt index 612512661..4cd9eb18f 100644 --- a/tests/_files/NamespacedBankAccount-text.txt +++ b/tests/_files/NamespacedBankAccount-text.txt @@ -1,14 +1,14 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 50.00% (5/10) + + Summary: + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 55.56% (5/9) SomeNamespace\BankAccount Methods: ( 0/ 0) Lines: ( 0/ 0) SomeNamespace\BankAccountTrait - Methods: 75.00% ( 3/ 4) Lines: 50.00% ( 5/ 10) + Methods: 75.00% ( 3/ 4) Lines: 55.56% ( 5/ 9) diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html b/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html index 646035749..05078012d 100644 --- a/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html +++ b/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html @@ -60,14 +60,14 @@
75.00%
3 / 4
CRAP -
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -88,15 +88,15 @@
75.00%
3 / 4
- 8.12 -
-
- 50.00% covered (danger) + 7.19 +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -138,7 +138,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -197,7 +197,7 @@ 6    public function getBalance() 7    { 8        return $this->balance; - 9    } + 9    } 10 11    protected function setBalance($balance) 12    { @@ -206,22 +206,23 @@ 15        } else { 16            throw new RuntimeException; 17        } - 18    } + 18    } 19 20    public function depositMoney($balance) 21    { 22        $this->setBalance($this->getBalance() + $balance); 23 24        return $this->getBalance(); - 25    } + 25    } 26 27    public function withdrawMoney($balance) 28    { 29        $this->setBalance($this->getBalance() - $balance); 30 31        return $this->getBalance(); - 32    } - 33} + 32        return $this->getBalance(); + 33    } + 34} diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html index e47929fbd..fc20fb36e 100644 --- a/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html +++ b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html @@ -57,7 +57,7 @@

Insufficient Coverage

- BankAccount50% + BankAccount55% @@ -74,7 +74,7 @@

Project Risks

- BankAccount8 + BankAccount7 @@ -226,7 +226,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[50,5,"BankAccount<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[55.555555555556,5,"BankAccount<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/index.html b/tests/_files/Report/HTML/CoverageForBankAccount/index.html index e0c9ed9d9..89ab27d54 100644 --- a/tests/_files/Report/HTML/CoverageForBankAccount/index.html +++ b/tests/_files/Report/HTML/CoverageForBankAccount/index.html @@ -42,15 +42,15 @@ - Total -
-
- 50.00% covered (danger) + Total +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
75.00% covered (warning) @@ -70,15 +70,15 @@ - BankAccount.php -
-
- 50.00% covered (danger) + BankAccount.php +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
75.00% covered (warning) diff --git a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html index 7d4cfffce..99192670d 100644 --- a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html +++ b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html @@ -42,15 +42,15 @@ - Total -
-
- 50.00% covered (danger) + Total +
+
+ 100.00% covered (success)
-
50.00%
-
1 / 2
+
100.00%
+
1 / 1
100.00% covered (success) @@ -65,15 +65,15 @@ - source_with_ignore.php -
-
- 50.00% covered (danger) + source_with_ignore.php +
+
+ 100.00% covered (success)
-
50.00%
-
1 / 2
+
100.00%
+
1 / 1
100.00% covered (success) diff --git a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html index d1218e2eb..58f568164 100644 --- a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html +++ b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html @@ -55,14 +55,14 @@
100.00%
1 / 1
CRAP -
-
- 50.00% covered (danger) +
+
+ 100.00% covered (success)
-
50.00%
-
1 / 2
+
100.00%
+
1 / 1
@@ -137,7 +137,7 @@ 3    // @codeCoverageIgnoreStart 4    print '*'; 5    // @codeCoverageIgnoreEnd - 6} + 6} 7 8/** 9 * @codeCoverageIgnore diff --git a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/dashboard.html b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/dashboard.html index c1246a182..6d77bc849 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/dashboard.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/dashboard.html @@ -57,7 +57,6 @@

Insufficient Coverage

- CoveredClassWithAnonymousFunctionInStaticMethod88% @@ -111,7 +110,6 @@

Insufficient Coverage

- runAnonymous88% @@ -156,7 +154,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,1,0,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,0,1], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -174,7 +172,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,1,0,0], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,0,1], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -224,7 +222,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[88.888888888889,1,"CoveredClassWithAnonymousFunctionInStaticMethod<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[100,1,"CoveredClassWithAnonymousFunctionInStaticMethod<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -248,7 +246,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[88.888888888889,1,"
CoveredClassWithAnonymousFunctionInStaticMethod::runAnonymous<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,1,"CoveredClassWithAnonymousFunctionInStaticMethod::runAnonymous<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.html b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.html index 222cec8c4..9626a7eea 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.html @@ -42,59 +42,59 @@ - Total -
-
- 88.89% covered (warning) + Total +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
-
-
- 0.00% covered (danger) +
100.00%
+
4 / 4
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
+
100.00%
+
1 / 1
-
source_with_class_and_anonymous_function.php -
-
- 88.89% covered (warning) + source_with_class_and_anonymous_function.php +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
-
-
- 0.00% covered (danger) +
100.00%
+
4 / 4
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
+
100.00%
+
1 / 1
diff --git a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html index e0a83a0a3..bbae23992 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html @@ -42,82 +42,82 @@ - Total -
-
- 0.00% covered (danger) + Total +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- CRAP -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ CRAP +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
- CoveredClassWithAnonymousFunctionInStaticMethod -
-
- 0.00% covered (danger) + CoveredClassWithAnonymousFunctionInStaticMethod +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 1.00 -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ 1 +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
-  runAnonymous -
-
- 0.00% covered (danger) +  runAnonymous +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 1.00 -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ 1 +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
@@ -135,15 +135,15 @@ 7        $filter = ['abc124', 'abc123', '123']; 8 9        array_walk( - 10            $filter, - 11            function (&$val, $key) { + 10            $filter, + 11            function (&$val, $key) { 12                $val = preg_replace('|[^0-9]|', '', $val); - 13            } - 14        ); + 13            } + 14        ); 15 16        // Should be covered 17        $extravar = true; - 18    } + 18    } 19} diff --git a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/index.html b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/index.html index b60a7d65b..72607caaf 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/index.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/index.html @@ -52,7 +52,7 @@
0.00%
-
0 / 5
+
0 / 4
0.00% covered (danger) @@ -91,7 +91,7 @@
0.00%
-
0 / 5
+
0 / 4
0.00% covered (danger) diff --git a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html index c0105b162..d82da91c5 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -163,7 +163,7 @@ 15    $a   = true ? true : false; 16    $b   = "{$a}"; 17    $c   = "${b}"; - 18} + 18} diff --git a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html index 2fbee3406..a95fbb002 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
diff --git a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html index aa088747f..c54d785b3 100644 --- a/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html +++ b/tests/_files/Report/HTML/PHP80AndBelow/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
diff --git a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/dashboard.html b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/dashboard.html index c1246a182..6d77bc849 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/dashboard.html +++ b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/dashboard.html @@ -57,7 +57,6 @@

Insufficient Coverage

- CoveredClassWithAnonymousFunctionInStaticMethod88% @@ -111,7 +110,6 @@

Insufficient Coverage

- runAnonymous88% @@ -156,7 +154,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,1,0,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,0,1], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -174,7 +172,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,1,0,0], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,0,1], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -224,7 +222,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[88.888888888889,1,"CoveredClassWithAnonymousFunctionInStaticMethod<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[100,1,"CoveredClassWithAnonymousFunctionInStaticMethod<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -248,7 +246,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[88.888888888889,1,"
CoveredClassWithAnonymousFunctionInStaticMethod::runAnonymous<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,1,"CoveredClassWithAnonymousFunctionInStaticMethod::runAnonymous<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.html b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.html index 222cec8c4..9626a7eea 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.html +++ b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.html @@ -42,59 +42,59 @@ - Total -
-
- 88.89% covered (warning) + Total +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
-
-
- 0.00% covered (danger) +
100.00%
+
4 / 4
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
+
100.00%
+
1 / 1
-
source_with_class_and_anonymous_function.php -
-
- 88.89% covered (warning) + source_with_class_and_anonymous_function.php +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
-
-
- 0.00% covered (danger) +
100.00%
+
4 / 4
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
+
100.00%
+
1 / 1
diff --git a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html index 72f19ae15..d1390f1e8 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html +++ b/tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html @@ -42,82 +42,82 @@ - Total -
-
- 0.00% covered (danger) + Total +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- CRAP -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ CRAP +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
- CoveredClassWithAnonymousFunctionInStaticMethod -
-
- 0.00% covered (danger) + CoveredClassWithAnonymousFunctionInStaticMethod +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 1.00 -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ 1 +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
-  runAnonymous -
-
- 0.00% covered (danger) +  runAnonymous +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 1.00 -
-
- 88.89% covered (warning) +
100.00%
+
1 / 1
+ 1 +
+
+ 100.00% covered (success)
-
88.89%
-
8 / 9
+
100.00%
+
4 / 4
@@ -135,15 +135,15 @@ 7        $filter = ['abc124', 'abc123', '123']; 8 9        array_walk( - 10            $filter, - 11            function (&$val, $key) { + 10            $filter, + 11            function (&$val, $key) { 12                $val = preg_replace('|[^0-9]|', '', $val); - 13            } - 14        ); + 13            } + 14        ); 15 16        // Should be covered 17        $extravar = true; - 18    } + 18    } 19} diff --git a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/index.html b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/index.html index b60a7d65b..72607caaf 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/index.html +++ b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/index.html @@ -52,7 +52,7 @@
0.00%
-
0 / 5
+
0 / 4
0.00% covered (danger) @@ -91,7 +91,7 @@
0.00%
-
0 / 5
+
0 / 4
0.00% covered (danger) diff --git a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html index 163e982b9..aee66088a 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html +++ b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -163,7 +163,7 @@ 15    $a   = true ? true : false; 16    $b   = "{$a}"; 17    $c   = "${b}"; - 18} + 18} diff --git a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html index 76857ba92..8368e45c0 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html +++ b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
diff --git a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html index 9418bca07..543f5109d 100644 --- a/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html +++ b/tests/_files/Report/HTML/PHP81AndUp/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html @@ -80,7 +80,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -117,7 +117,7 @@
0.00%
-
0 / 5
+
0 / 4
diff --git a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php.html b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php.html index 3847b4399..60f633a9b 100644 --- a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php.html +++ b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php.html @@ -78,14 +78,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -123,14 +123,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -204,7 +204,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -295,7 +295,7 @@ 6    public function getBalance() 7    { 8        return $this->balance; - 9    } + 9    } 10 11    protected function setBalance($balance) 12    { @@ -304,22 +304,23 @@ 15        } else { 16            throw new RuntimeException; 17        } - 18    } + 18    } 19 20    public function depositMoney($balance) 21    { 22        $this->setBalance($this->getBalance() + $balance); 23 24        return $this->getBalance(); - 25    } + 25    } 26 27    public function withdrawMoney($balance) 28    { 29        $this->setBalance($this->getBalance() - $balance); 30 31        return $this->getBalance(); - 32    } - 33} + 32        return $this->getBalance(); + 33    } + 34} diff --git a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_branch.html b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_branch.html index 7815dc9e9..11336c19e 100644 --- a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_branch.html +++ b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_branch.html @@ -78,14 +78,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -123,14 +123,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -204,7 +204,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -318,8 +318,9 @@ 29%s 30 31%s - 32%s - 33%s + 32        return $this->getBalance(); + 33    } + 34} @@ -393,23 +394,6 @@
BankAccoun - - - -
- - - - +%a diff --git a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_path.html b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_path.html index 67cbe9943..681005e0e 100644 --- a/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_path.html +++ b/tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_path.html @@ -78,14 +78,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -123,14 +123,14 @@
42.86%
3 / 7
-
-
- 50.00% covered (danger) +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
@@ -204,7 +204,7 @@
0.00%
-
0 / 5
+
0 / 4
@@ -319,7 +319,8 @@ 30 31%s 32%s - 33%s + 33    } + 34} @@ -386,23 +387,6 @@
BankAccoun - - - -
- - - - +%a diff --git a/tests/_files/Report/HTML/PathCoverageForBankAccount/index.html b/tests/_files/Report/HTML/PathCoverageForBankAccount/index.html index 8400c9b4b..c31d0b7a7 100644 --- a/tests/_files/Report/HTML/PathCoverageForBankAccount/index.html +++ b/tests/_files/Report/HTML/PathCoverageForBankAccount/index.html @@ -44,15 +44,15 @@ - Total -
-
- 50.00% covered (danger) + Total +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
42.86% covered (danger) @@ -88,15 +88,15 @@ - BankAccount.php [line] [branch] [path] -
-
- 50.00% covered (danger) + BankAccount.php [line] [branch] [path] +
+
+ 55.56% covered (warning)
-
50.00%
-
5 / 10
+
55.56%
+
5 / 9
42.86% covered (danger) diff --git a/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml index 577bc4cc9..0731a8335 100644 --- a/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml +++ b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml @@ -2,18 +2,18 @@ - + - + - + - + @@ -249,13 +249,24 @@ ; + + return + + $this + -> + getBalance + ( + ) + ; + + } - + } - + diff --git a/tests/_files/Report/XML/CoverageForBankAccount/index.xml b/tests/_files/Report/XML/CoverageForBankAccount/index.xml index df433b085..b8d20f33e 100644 --- a/tests/_files/Report/XML/CoverageForBankAccount/index.xml +++ b/tests/_files/Report/XML/CoverageForBankAccount/index.xml @@ -13,7 +13,7 @@ - + @@ -21,7 +21,7 @@ - + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml index 65c08f517..ff573b704 100644 --- a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml @@ -10,7 +10,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml index a2b6623b4..b4d163c63 100644 --- a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml @@ -2,7 +2,7 @@ - + diff --git a/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.xml b/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.xml index 0ae6bdea3..ad86c96f4 100644 --- a/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.xml +++ b/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.xml @@ -10,18 +10,18 @@ - - + + - + - - + + - + diff --git a/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml b/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml index 8757aa362..ab4f84275 100644 --- a/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml +++ b/tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml @@ -2,15 +2,15 @@ - - + + - + - + - + @@ -19,24 +19,12 @@ - - - - - - - - - - - - diff --git a/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.xml b/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.xml index 0ae6bdea3..ad86c96f4 100644 --- a/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.xml +++ b/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.xml @@ -10,18 +10,18 @@ - - + + - + - - + + - + diff --git a/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml b/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml index f4275cd8b..a767fa117 100644 --- a/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml +++ b/tests/_files/Report/XML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml @@ -2,15 +2,15 @@ - - + + - + - + - + @@ -19,24 +19,12 @@ - - - - - - - - - - - - diff --git a/tests/_files/class-with-anonymous-function-clover.xml b/tests/_files/class-with-anonymous-function-clover.xml index 785195405..223ebebec 100644 --- a/tests/_files/class-with-anonymous-function-clover.xml +++ b/tests/_files/class-with-anonymous-function-clover.xml @@ -3,20 +3,15 @@ - + - + - - - - - - + - + diff --git a/tests/_files/class-with-anonymous-function-cobertura.xml b/tests/_files/class-with-anonymous-function-cobertura.xml index fa7b8a2c4..874f85080 100644 --- a/tests/_files/class-with-anonymous-function-cobertura.xml +++ b/tests/_files/class-with-anonymous-function-cobertura.xml @@ -1,38 +1,28 @@ - + %s - + - + - + - - - - - - - - - - diff --git a/tests/_files/class-with-anonymous-function-crap4j.xml b/tests/_files/class-with-anonymous-function-crap4j.xml index 2d60e6215..11ace3eb9 100644 --- a/tests/_files/class-with-anonymous-function-crap4j.xml +++ b/tests/_files/class-with-anonymous-function-crap4j.xml @@ -19,7 +19,7 @@ runAnonymous() 1 1 - 88.89 + 100 0 diff --git a/tests/_files/class-with-anonymous-function-text.txt b/tests/_files/class-with-anonymous-function-text.txt index fc46ef929..ca6d0b965 100644 --- a/tests/_files/class-with-anonymous-function-text.txt +++ b/tests/_files/class-with-anonymous-function-text.txt @@ -1,12 +1,12 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/1) - Methods: 0.00% (0/1) - Lines: 88.89% (8/9) + + Summary: + Classes: 100.00% (1/1) + Methods: 100.00% (1/1) + Lines: 100.00% (4/4) CoveredClassWithAnonymousFunctionInStaticMethod - Methods: 0.00% ( 0/ 1) Lines: 88.89% ( 8/ 9) + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 4/ 4) diff --git a/tests/_files/ignored-lines-clover.xml b/tests/_files/ignored-lines-clover.xml index 0b619ef30..1341bf33d 100644 --- a/tests/_files/ignored-lines-clover.xml +++ b/tests/_files/ignored-lines-clover.xml @@ -9,9 +9,8 @@ - - + - + diff --git a/tests/_files/ignored-lines-cobertura.xml b/tests/_files/ignored-lines-cobertura.xml index e0f9c4c38..3ec411f67 100644 --- a/tests/_files/ignored-lines-cobertura.xml +++ b/tests/_files/ignored-lines-cobertura.xml @@ -1,11 +1,11 @@ - + %s - + diff --git a/tests/_files/ignored-lines-text.txt b/tests/_files/ignored-lines-text.txt index 6e8e1494f..55f57afbc 100644 --- a/tests/_files/ignored-lines-text.txt +++ b/tests/_files/ignored-lines-text.txt @@ -4,7 +4,7 @@ Code Coverage Report:%w %s %w Summary:%w - Classes: (0/0) - Methods: (0/0) - Lines: 50.00% (1/2) + Classes: (0/0) + Methods: (0/0) + Lines: 100.00% (1/1) diff --git a/tests/_files/source_with_heavy_indentation.php b/tests/_files/source_with_heavy_indentation.php new file mode 100644 index 000000000..bf4b123af --- /dev/null +++ b/tests/_files/source_with_heavy_indentation.php @@ -0,0 +1,79 @@ +state + or ( + $this->isBar() + and \in_array($this->state, [ + AType::A, + AType::B, + ], true) + ) + or (\in_array($this->type, [BType::X, BType::Y], true) + and \in_array($this->state, [ + AType::C, + AType::D, + AType::toOutput($this->state), + ], true)) + || + \in_array + ( + 1 + , + [ + AType::A + , + 2 + , + $v2 + = + PHP_INT_MAX + , + $this + -> + state + , + $v3 + = + 1 + => + 2 + , + uniqid() + => + true + , + self + :: + $state + ] + , + (bool) + AType::A + ) + ; + } + + public function isTwo(): bool + { + return \in_array($this->state, [ + AType::A, + AType::B, + ], true); + } + + private static $staticState = 1; + private const CONST_STATE = 1.1; +} diff --git a/tests/tests/BuilderTest.php b/tests/tests/BuilderTest.php index e91484c5c..18399d641 100644 --- a/tests/tests/BuilderTest.php +++ b/tests/tests/BuilderTest.php @@ -33,7 +33,7 @@ public function testSomething(): void $expectedPath = rtrim(TEST_FILES_PATH, DIRECTORY_SEPARATOR); $this->assertEquals($expectedPath, $root->name()); $this->assertEquals($expectedPath, $root->pathAsString()); - $this->assertEquals(10, $root->numberOfExecutableLines()); + $this->assertEquals(9, $root->numberOfExecutableLines()); $this->assertEquals(5, $root->numberOfExecutedLines()); $this->assertEquals(1, $root->numberOfClasses()); $this->assertEquals(0, $root->numberOfTestedClasses()); @@ -41,7 +41,7 @@ public function testSomething(): void $this->assertEquals(3, $root->numberOfTestedMethods()); $this->assertEquals('0.00%', $root->percentageOfTestedClasses()->asString()); $this->assertEquals('75.00%', $root->percentageOfTestedMethods()->asString()); - $this->assertEquals('50.00%', $root->percentageOfExecutedLines()->asString()); + $this->assertEquals('55.56%', $root->percentageOfExecutedLines()->asString()); $this->assertEquals(0, $root->numberOfFunctions()); $this->assertEquals(0, $root->numberOfTestedFunctions()); $this->assertNull($root->parent()); @@ -74,7 +74,7 @@ public function testSomething(): void 'signature' => 'setBalance($balance)', 'startLine' => 11, 'endLine' => 18, - 'executableLines' => 5, + 'executableLines' => 4, 'executedLines' => 0, 'executableBranches' => 0, 'executedBranches' => 0, @@ -107,7 +107,7 @@ public function testSomething(): void 'withdrawMoney' => [ 'signature' => 'withdrawMoney($balance)', 'startLine' => 27, - 'endLine' => 32, + 'endLine' => 33, 'executableLines' => 2, 'executedLines' => 2, 'executableBranches' => 0, @@ -123,15 +123,15 @@ public function testSomething(): void ], ], 'startLine' => 2, - 'executableLines' => 10, + 'executableLines' => 9, 'executedLines' => 5, 'executableBranches' => 0, 'executedBranches' => 0, 'executablePaths' => 0, 'executedPaths' => 0, 'ccn' => 5, - 'coverage' => 50, - 'crap' => '8.12', + 'coverage' => 55.555555555556, + 'crap' => '7.19', 'link' => 'BankAccount.php.html#2', 'className' => 'BankAccount', 'namespace' => '', diff --git a/tests/tests/CodeCoverageTest.php b/tests/tests/CodeCoverageTest.php index 14df3f824..8de789819 100644 --- a/tests/tests/CodeCoverageTest.php +++ b/tests/tests/CodeCoverageTest.php @@ -93,6 +93,34 @@ public function testWhitelistFiltering(): void $this->assertNotContains(TEST_FILES_PATH . 'CoverageClassTest.php', $this->coverage->getData()->coveredFiles()); } + public function testExcludeNonExecutableLines(): void + { + $this->coverage->filter()->includeFile(TEST_FILES_PATH . 'BankAccount.php'); + + $data = RawCodeCoverageData::fromXdebugWithoutPathCoverage([ + TEST_FILES_PATH . 'BankAccount.php' => array_fill(1, 100, -1), + ]); + + $this->coverage->append($data, 'A test', true); + + $expectedLineCoverage = [ + TEST_FILES_PATH . 'BankAccount.php' => [ + 8 => [], + 13 => [], + 14 => [], + 15 => [], + 16 => [], + 22 => [], + 24 => [], + 29 => [], + 31 => [], + 32 => [], + ], + ]; + + $this->assertEquals($expectedLineCoverage, $this->coverage->getData()->lineCoverage()); + } + public function testMerge(): void { $coverage = $this->getLineCoverageForBankAccountForFirstTwoTests(); diff --git a/tests/tests/RawCodeCoverageDataTest.php b/tests/tests/RawCodeCoverageDataTest.php index 9c0b554e6..e0738e09f 100644 --- a/tests/tests/RawCodeCoverageDataTest.php +++ b/tests/tests/RawCodeCoverageDataTest.php @@ -211,9 +211,9 @@ public function testKeepCoverageDataOnlyForLines(): void $dataObject = RawCodeCoverageData::fromXdebugWithoutPathCoverage($lineDataFromDriver); - $dataObject->keepCoverageDataOnlyForLines('/some/path/SomeClass.php', [9, 13]); - $dataObject->keepCoverageDataOnlyForLines('/some/path/SomeOtherClass.php', [999]); - $dataObject->keepCoverageDataOnlyForLines('/some/path/AnotherClass.php', [28]); + $dataObject->keepLineCoverageDataOnlyForLines('/some/path/SomeClass.php', [9, 13]); + $dataObject->keepLineCoverageDataOnlyForLines('/some/path/SomeOtherClass.php', [999]); + $dataObject->keepLineCoverageDataOnlyForLines('/some/path/AnotherClass.php', [28]); $this->assertEquals($expectedFilterResult, $dataObject->lineCoverage()); } @@ -270,6 +270,7 @@ public function testUseStatementsAreUncovered(): void [ 12, 14, + 15, 18, ], array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingUncoveredFileAnalyser)->lineCoverage()[$file]) @@ -296,6 +297,7 @@ public function testInterfacesAreUncovered(): void [ 7, 9, + 10, 13, ], array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingUncoveredFileAnalyser)->lineCoverage()[$file]) @@ -321,6 +323,36 @@ public function testInlineCommentsKeepTheLine(): void ); } + public function testHeavyIndentationIsHandledCorrectly(): void + { + $file = TEST_FILES_PATH . 'source_with_heavy_indentation.php'; + + $this->assertEquals( + [ + 9, + 15, + 16, + 18, + 19, + 24, + 25, + 28, + 31, + 33, + 38, + 40, + 46, + 48, + 50, + 52, + 54, + 60, + 71, + ], + array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingUncoveredFileAnalyser)->lineCoverage()[$file]) + ); + } + public function testCoverageForFileWithInlineAnnotations(): void { $filename = TEST_FILES_PATH . 'source_with_oneline_annotations.php';