From c3a4bdfd815b1bc1790475ace6b4c715171fc857 Mon Sep 17 00:00:00 2001 From: aon4o Date: Sat, 25 Jan 2025 00:50:58 +0200 Subject: [PATCH 1/2] Added handling for --compact parameter --- src/Plugin.php | 13 +++++++++++++ tests/Plugin.php | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index 402101c..0b11abf 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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. */ @@ -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(); @@ -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); diff --git a/tests/Plugin.php b/tests/Plugin.php index 27a76c9..1d17bb0 100644 --- a/tests/Plugin.php +++ b/tests/Plugin.php @@ -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', + ); +}); + test('it can output to json', function () { $output = new BufferedOutput; $plugin = new class($output) extends Plugin From a3cfcb562a6a781a6548c6b76d7d3d48414e7c02 Mon Sep 17 00:00:00 2001 From: aon4o Date: Sat, 25 Jan 2025 01:26:07 +0200 Subject: [PATCH 2/2] Test 'output with --compact' updated --- tests/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Plugin.php b/tests/Plugin.php index 1d17bb0..3a49659 100644 --- a/tests/Plugin.php +++ b/tests/Plugin.php @@ -41,7 +41,7 @@ public function exit(int $code): never '.. co14 87', '.. rt12 75', '.. pa12 87', - ); + )->not->toContain('.. 100%'); }); test('it can output to json', function () {