From 4079a08f5f35eb1694bfd1a4ec153afa4256a189 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 23 Jan 2025 13:59:51 +0000 Subject: [PATCH] feat: adds `--compact` to coverage --- src/Plugins/Coverage.php | 11 ++++++++++- src/Support/Coverage.php | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Plugins/Coverage.php b/src/Plugins/Coverage.php index 75b06320..a5061d25 100644 --- a/src/Plugins/Coverage.php +++ b/src/Plugins/Coverage.php @@ -37,6 +37,11 @@ final class Coverage implements AddsOutput, HandlesArguments */ public bool $coverage = false; + /** + * Whether it should show the coverage or not. + */ + public bool $compact = false; + /** * The minimum coverage. */ @@ -124,6 +129,10 @@ final class Coverage implements AddsOutput, HandlesArguments $this->coverageExactly = (float) $exactlyOption; } + if ($_SERVER['COLLISION_PRINTER_COMPACT'] ?? false) { + $this->compact = true; + } + return $originals; } @@ -144,7 +153,7 @@ final class Coverage implements AddsOutput, HandlesArguments exit(1); } - $coverage = \Pest\Support\Coverage::report($this->output); + $coverage = \Pest\Support\Coverage::report($this->output, $this->compact); $exitCode = (int) ($coverage < $this->coverageMin); if ($exitCode === 0 && $this->coverageExactly !== null) { diff --git a/src/Support/Coverage.php b/src/Support/Coverage.php index 302e00b1..955bbfc4 100644 --- a/src/Support/Coverage.php +++ b/src/Support/Coverage.php @@ -74,7 +74,7 @@ final class Coverage * Reports the code coverage report to the * console and returns the result in float. */ - public static function report(OutputInterface $output): float + public static function report(OutputInterface $output, bool $compact = false): float { if (! file_exists($reportPath = self::getPath())) { if (self::usingXdebug()) { @@ -113,6 +113,10 @@ final class Coverage ? '100.0' : number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', ''); + if ($percentage === '100.0' && $compact) { + continue; + } + $uncoveredLines = ''; $percentageOfExecutedLinesAsString = $file->percentageOfExecutedLines()->asString();