Skip to content

Commit 77eb4c0

Browse files
authored
Merge pull request #38 from aon4o/3.x
Added handling for `--compact` parameter
2 parents 2616d6b + a3cfcb5 commit 77eb4c0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Plugin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class Plugin implements HandlesArguments
3838
*/
3939
private Logger $coverageLogger;
4040

41+
/**
42+
* Whether to use compact output.
43+
*/
44+
private bool $compact = false;
45+
4146
/**
4247
* Creates a new Plugin instance.
4348
*/
@@ -106,6 +111,10 @@ public function handleArguments(array $arguments): array
106111

107112
$this->coverageLogger = new JsonLogger(explode('=', $argument)[1], $this->coverageMin);
108113
}
114+
115+
if (str_starts_with($argument, '--compact')) {
116+
$this->compact = true;
117+
}
109118
}
110119

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

159+
if ($this->compact && $uncoveredLines === []) {
160+
return;
161+
}
162+
150163
$color = $uncoveredLines === [] ? 'green' : 'yellow';
151164

152165
$this->coverageLogger->append($path, $uncoveredLines, $uncoveredLinesIgnored, $result->totalCoverage);

tests/Plugin.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ public function exit(int $code): never
2424
);
2525
});
2626

27+
test('output with --compact', function () {
28+
$output = new BufferedOutput;
29+
$plugin = new class($output) extends Plugin
30+
{
31+
public function exit(int $code): never
32+
{
33+
throw new Exception($code);
34+
}
35+
};
36+
37+
expect(fn () => $plugin->handleArguments(['--type-coverage', '--compact']))->toThrow(Exception::class, 0)
38+
->and($output->fetch())->toContain(
39+
'.. pr12 87',
40+
'.. co14, pr16, pa18, pa18, rt18 12',
41+
'.. co14 87',
42+
'.. rt12 75',
43+
'.. pa12 87',
44+
)->not->toContain('.. 100%');
45+
});
46+
2747
test('it can output to json', function () {
2848
$output = new BufferedOutput;
2949
$plugin = new class($output) extends Plugin

0 commit comments

Comments
 (0)