From 9fa2608e9aace7fbc97afe4daee190d647ee8604 Mon Sep 17 00:00:00 2001 From: nnatter Date: Wed, 5 Feb 2020 15:25:29 +0100 Subject: [PATCH] Output total coverage for all included files at end of script (#1) --- bin/code-coverage-checker.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/code-coverage-checker.php b/bin/code-coverage-checker.php index 6ef01b4..904c6a7 100644 --- a/bin/code-coverage-checker.php +++ b/bin/code-coverage-checker.php @@ -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 @@ -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); @@ -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(); @@ -127,6 +141,7 @@ function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric $path, $threshold )); + $io->newLine(1); return 1; } @@ -137,6 +152,7 @@ function assertCodeCoverage(CodeCoverage $coverage, string $path, string $metric $path, $threshold )); + $io->newLine(1); return 0; } @@ -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