Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling for --compact parameter #38

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class Plugin implements HandlesArguments
*/
private Logger $coverageLogger;

/**
* Whether to use compact output.
*/
private bool $compact = false;

/**
* Creates a new Plugin instance.
*/
Expand Down Expand Up @@ -106,6 +111,10 @@ public function handleArguments(array $arguments): array

$this->coverageLogger = new JsonLogger(explode('=', $argument)[1], $this->coverageMin);
}

if (str_starts_with($argument, '--compact')) {
$this->compact = true;
}
}

$source = ConfigurationSourceDetector::detect();
Expand Down Expand Up @@ -147,6 +156,10 @@ function (Result $result) use (&$totals): void {
$uncoveredLinesIgnored[] = $error->getShortType().$error->line;
}

if ($this->compact && $uncoveredLines === []) {
return;
}

$color = $uncoveredLines === [] ? 'green' : 'yellow';

$this->coverageLogger->append($path, $uncoveredLines, $uncoveredLinesIgnored, $result->totalCoverage);
Expand Down
20 changes: 20 additions & 0 deletions tests/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ public function exit(int $code): never
);
});

test('output with --compact', function () {
$output = new BufferedOutput;
$plugin = new class($output) extends Plugin
{
public function exit(int $code): never
{
throw new Exception($code);
}
};

expect(fn () => $plugin->handleArguments(['--type-coverage', '--compact']))->toThrow(Exception::class, 0)
->and($output->fetch())->toContain(
'.. pr12 87',
'.. co14, pr16, pa18, pa18, rt18 12',
'.. co14 87',
'.. rt12 75',
'.. pa12 87',
)->not->toContain('.. 100%');
});

test('it can output to json', function () {
$output = new BufferedOutput;
$plugin = new class($output) extends Plugin
Expand Down