Skip to content

Commit 23b58a5

Browse files
Merge branch 'json-format-fix-no-errors' into gitlab-output-format
# Conflicts: # tests/E2E/Cli/CheckCommandTest.php
2 parents 45871d7 + 3681bac commit 23b58a5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/CLI/Command/Check.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
200200
return self::ERROR_CODE;
201201
}
202202

203-
$this->printNoViolationsDetectedMessage($output, $onlyErrors);
203+
$this->printNoViolationsDetectedMessage($output, $onlyErrors, $format);
204204

205205
if (!$onlyErrors) {
206206
$this->printExecutionTime($output, $startTime);
@@ -266,6 +266,7 @@ private function printViolations(Violations $violations, OutputInterface $output
266266
if (!$onlyErrors) {
267267
$output->writeln('<error>ERRORS!</error>');
268268
}
269+
269270
$output->writeln(sprintf('%s', $violations->toString($format)));
270271
if (!$onlyErrors) {
271272
$output->writeln(sprintf('<error>%s VIOLATIONS DETECTED!</error>', \count($violations)));
@@ -280,10 +281,12 @@ private function printParsedErrors(ParsingErrors $parsingErrors, OutputInterface
280281
$output->writeln(sprintf('%s', $parsingErrors->toString()));
281282
}
282283

283-
private function printNoViolationsDetectedMessage(OutputInterface $output, bool $onlyErrors = false): void
284+
private function printNoViolationsDetectedMessage(OutputInterface $output, bool $onlyErrors = false, string $format = Printer::FORMAT_TEXT): void
284285
{
285286
if (!$onlyErrors) {
286287
$output->writeln('<info>NO VIOLATIONS DETECTED!</info>');
288+
} elseif (Printer::FORMAT_JSON === $format) {
289+
$output->writeln('<info>[]</info>');
287290
}
288291
}
289292
}

tests/E2E/Cli/CheckCommandTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ public function test_json_format_output(): void
179179
$this->assertJson($display);
180180
}
181181

182+
public function test_json_format_output_no_errors(): void
183+
{
184+
$configFilePath = __DIR__.'/../_fixtures/configMvcWithoutErrors.php';
185+
186+
$cmdTester = $this->runCheck($configFilePath, null, null, false, false, false, 'json');
187+
188+
$this->assertCheckHasSuccess($cmdTester);
189+
190+
$display = $cmdTester->getDisplay();
191+
192+
$this->assertJson($display);
193+
194+
$json = json_decode($display, true);
195+
$this->assertCount(0, $json);
196+
}
197+
182198
public function test_gitlab_format_output(): void
183199
{
184200
$configFilePath = __DIR__.'/../_fixtures/configMvcForYieldBug.php';

0 commit comments

Comments
 (0)