Skip to content

Commit

Permalink
Do not add methods with 0% coverage to TestsLocations to prevent wa…
Browse files Browse the repository at this point in the history
…sting of resources (#1633)

Consider the following XML coverage file https://github.com/infection/infection/blob/de7d826e770fbb0400c91272e5460e1ff880e65f/tests/phpunit/Fixtures/Files/phpunit/coverage/coverage-xml/FirstLevel/firstLevel.php.xml#L20 where `mutate()` method has 0% coverage.

There is no need to add this method to `TestsLocations` as later no tests will be found for its lines, so that the following code will just waste resources:

https://github.com/infection/infection/blob/de7d826e770fbb0400c91272e5460e1ff880e65f/src/TestFramework/Coverage/XmlReport/TestLocator.php#L117-L130

because since method is not covered - lines inside it also are not covered (check the XML coverage above)
  • Loading branch information
maks-rafalko committed Jan 1, 2022
1 parent de7d826 commit 0590b79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/TestFramework/Coverage/XmlReport/XmlCoverageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ private static function &collectMethodsCoverageData(DOMNodeList $methodsCoverage
$methodsCoverage = [];

foreach ($methodsCoverageNodes as $methodsCoverageNode) {
if ((int) $methodsCoverageNode->getAttribute('coverage') === 0) {
continue;
}

$methodName = $methodsCoverageNode->getAttribute('name');

$start = $methodsCoverageNode->getAttribute('start');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ public static function provideFixtures(): iterable
],
],
'byMethod' => [
'mutate' => [
'startLine' => 19,
'endLine' => 22,
],
'shouldMutate' => [
'startLine' => 24,
'endLine' => 35,
Expand Down Expand Up @@ -137,10 +133,6 @@ public static function provideFixtures(): iterable
],
],
'byMethod' => [
'mutate' => [
'startLine' => 19,
'endLine' => 22,
],
'shouldMutate' => [
'startLine' => 24,
'endLine' => 35,
Expand Down Expand Up @@ -170,10 +162,6 @@ public static function provideFixtures(): iterable
],
],
'byMethod' => [
'mutate' => [
'startLine' => 19,
'endLine' => 22,
],
'shouldMutate' => [
'startLine' => 24,
'endLine' => 35,
Expand Down

0 comments on commit 0590b79

Please sign in to comment.