feat: adds --compact to coverage

This commit is contained in:
Nuno Maduro
2025-01-23 13:59:51 +00:00
parent e4aab77a34
commit 4079a08f5f
2 changed files with 15 additions and 2 deletions

View File

@ -37,6 +37,11 @@ final class Coverage implements AddsOutput, HandlesArguments
*/ */
public bool $coverage = false; public bool $coverage = false;
/**
* Whether it should show the coverage or not.
*/
public bool $compact = false;
/** /**
* The minimum coverage. * The minimum coverage.
*/ */
@ -124,6 +129,10 @@ final class Coverage implements AddsOutput, HandlesArguments
$this->coverageExactly = (float) $exactlyOption; $this->coverageExactly = (float) $exactlyOption;
} }
if ($_SERVER['COLLISION_PRINTER_COMPACT'] ?? false) {
$this->compact = true;
}
return $originals; return $originals;
} }
@ -144,7 +153,7 @@ final class Coverage implements AddsOutput, HandlesArguments
exit(1); exit(1);
} }
$coverage = \Pest\Support\Coverage::report($this->output); $coverage = \Pest\Support\Coverage::report($this->output, $this->compact);
$exitCode = (int) ($coverage < $this->coverageMin); $exitCode = (int) ($coverage < $this->coverageMin);
if ($exitCode === 0 && $this->coverageExactly !== null) { if ($exitCode === 0 && $this->coverageExactly !== null) {

View File

@ -74,7 +74,7 @@ final class Coverage
* Reports the code coverage report to the * Reports the code coverage report to the
* console and returns the result in float. * 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 (! file_exists($reportPath = self::getPath())) {
if (self::usingXdebug()) { if (self::usingXdebug()) {
@ -113,6 +113,10 @@ final class Coverage
? '100.0' ? '100.0'
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', ''); : number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
if ($percentage === '100.0' && $compact) {
continue;
}
$uncoveredLines = ''; $uncoveredLines = '';
$percentageOfExecutedLinesAsString = $file->percentageOfExecutedLines()->asString(); $percentageOfExecutedLinesAsString = $file->percentageOfExecutedLines()->asString();