Skip to content

Commit

Permalink
feat: adds --compact to coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jan 23, 2025
1 parent e4aab77 commit 4079a08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/Plugins/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -124,6 +129,10 @@ public function handleArguments(array $originals): array
$this->coverageExactly = (float) $exactlyOption;
}

if ($_SERVER['COLLISION_PRINTER_COMPACT'] ?? false) {
$this->compact = true;
}

return $originals;
}

Expand All @@ -144,7 +153,7 @@ public function addOutput(int $exitCode): int
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) {
Expand Down
6 changes: 5 additions & 1 deletion src/Support/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function usingXdebug(): bool
* 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()) {
Expand Down Expand Up @@ -113,6 +113,10 @@ public static function report(OutputInterface $output): float
? '100.0'
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');

if ($percentage === '100.0' && $compact) {
continue;
}

$uncoveredLines = '';

$percentageOfExecutedLinesAsString = $file->percentageOfExecutedLines()->asString();
Expand Down

0 comments on commit 4079a08

Please sign in to comment.