Skip to content

Commit

Permalink
Output total coverage for all included files at end of script (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter authored Feb 5, 2020
1 parent e7373ac commit 9fa2608
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions bin/code-coverage-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
/** @var CodeCoverage $coverage */
$coverage = require $coverageReportPath;

$exit = 0;

$paths = $input->getArgument('paths');

// Check all root paths if no paths are given
Expand All @@ -85,15 +83,29 @@
}
}

$totalExecutableLines = 0;
$totalCoveredLines = 0;
$exit = 0;

foreach ($paths as $path) {
$exit += assertCodeCoverage($coverage, $path, $metric, $threshold);
}

$message = sprintf(
'Line Coverage for all included files: %.2F%% (%d/%d).',
$totalCoveredLines / $totalExecutableLines * 100,
$totalCoveredLines,
$totalExecutableLines,
);
$io->block($message, 'INFO', 'fg=black;bg=white', ' ', true);

exit($exit);

function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric, float $threshold)
{
global $io;
global $totalExecutableLines;
global $totalCoveredLines;

$rootReport = $coverage->getReport();
$pathReport = getReportForPath($rootReport, $path);
Expand All @@ -105,6 +117,8 @@ function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric
}

printCodeCoverageReport($pathReport);
$totalExecutableLines = $totalExecutableLines + $pathReport->getNumExecutableLines();
$totalCoveredLines = $totalCoveredLines + $pathReport->getNumExecutedLines();

if ('line' === $metric) {
$reportedCoverage = $pathReport->getLineExecutedPercent();
Expand All @@ -127,6 +141,7 @@ function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric
$path,
$threshold
));
$io->newLine(1);

return 1;
}
Expand All @@ -137,6 +152,7 @@ function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric
$path,
$threshold
));
$io->newLine(1);

return 0;
}
Expand Down Expand Up @@ -172,7 +188,7 @@ function printCodeCoverageReport(Directory $pathReport): void

$io->title('Code coverage report for directory "' . $pathReport->getPath() . '"');
$table->render();
$io->newLine(2);
$io->newLine(1);
}

function getReportForPath(Directory $rootReport, string $path): ?Directory
Expand Down

0 comments on commit 9fa2608

Please sign in to comment.