Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Extractor/PhpUnitCoverageExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ private function extractFileCoverages(

$executableLines = [];
foreach ($fileCoverage as $lineNumber => $tests) {
if ($tests === null) {
continue; // dead (unreachable) line, PHPUnit reports skip it too
}

if (!is_array($tests)) {
throw new LogicException("Invalid coverage file: '{$coverageFile}'. Expected array under {$filePath} and #$lineNumber, got " . get_debug_type($tests));
throw new LogicException("Invalid coverage file: '{$coverageFile}'. Expected array or null under {$filePath} and #$lineNumber, got " . get_debug_type($tests));
}

$executableLines[] = new ExecutableLine((int) $lineNumber, count($tests));
Expand Down
16 changes: 16 additions & 0 deletions tests/Extractor/PhpUnitCoverageExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ public function testCovFileFromPhpCodeCoverage14WithEmptyBasePath(): void
self::assertSame('tests/_fixtures/Sample.php', $result[0]->filePath);
}

public function testSkipsDeadLines(): void
{
$data = new ProcessedCodeCoverageData();
$data->setLineCoverage(['Sample.php' => [8 => [], 9 => null, 10 => []]]);

$extractor = new PhpUnitCoverageExtractor();
$result = $extractor->getCoverage($this->writeCovFile([
'buildInformation' => [],
'basePath' => '',
'codeCoverage' => $data,
'testResults' => [],
]));

self::assertSame(['Sample.php' => [8 => 0, 10 => 0]], $this->toHitsMap($result));
}

public function testInvalidCovFile(): void
{
$extractor = new PhpUnitCoverageExtractor();
Expand Down
Loading