diff --git a/src/Command/TwigCsFixerCommand.php b/src/Command/TwigCsFixerCommand.php index 6322e5aa..d671f456 100644 --- a/src/Command/TwigCsFixerCommand.php +++ b/src/Command/TwigCsFixerCommand.php @@ -70,6 +70,12 @@ protected function configure(): void InputOption::VALUE_NONE, 'Disable cache while running the fixer' ), + new InputOption( + 'debug', + '', + InputOption::VALUE_NONE, + 'Display more technical informations', + ), ]) ; } @@ -129,7 +135,7 @@ private function runLinter(Config $config, InputInterface $input, OutputInterfac $reporterFactory = new ReporterFactory(); $reporter = $reporterFactory->getReporter($input->getOption('report')); - $reporter->display($output, $report, $input->getOption('level')); + $reporter->display($output, $report, $input->getOption('level'), $input->getOption('debug')); return $report; } diff --git a/src/Report/Reporter/CheckstyleReporter.php b/src/Report/Reporter/CheckstyleReporter.php index 5aff7409..fbea00b1 100644 --- a/src/Report/Reporter/CheckstyleReporter.php +++ b/src/Report/Reporter/CheckstyleReporter.php @@ -12,8 +12,12 @@ final class CheckstyleReporter implements ReporterInterface { public const NAME = 'checkstyle'; - public function display(OutputInterface $output, Report $report, ?string $level = null): void - { + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void { $text = ''."\n"; $text .= ''."\n"; @@ -38,7 +42,7 @@ public function display(OutputInterface $output, Report $report, ?string $level $text .= ' column="'.$linePosition.'"'; } $text .= ' severity="'.strtolower(Violation::getLevelAsString($violation->getLevel())).'"'; - $text .= ' message="'.$this->xmlEncode($violation->getMessage()).'"'; + $text .= ' message="'.$this->xmlEncode($violation->getDebugMessage($debug)).'"'; if (null !== $ruleName) { $text .= ' source="'.$ruleName.'"'; } diff --git a/src/Report/Reporter/GithubReporter.php b/src/Report/Reporter/GithubReporter.php index 25089f55..4fbcf061 100644 --- a/src/Report/Reporter/GithubReporter.php +++ b/src/Report/Reporter/GithubReporter.php @@ -17,8 +17,12 @@ final class GithubReporter implements ReporterInterface { public const NAME = 'github'; - public function display(OutputInterface $output, Report $report, ?string $level = null): void - { + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void { $violations = $report->getViolations($level); foreach ($violations as $violation) { $text = match ($violation->getLevel()) { @@ -40,7 +44,7 @@ public function display(OutputInterface $output, Report $report, ?string $level // newlines need to be encoded // see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448 - $text .= '::'.str_replace("\n", '%0A', $violation->getMessage()); + $text .= '::'.str_replace("\n", '%0A', $violation->getDebugMessage($debug)); $output->writeln($text); } diff --git a/src/Report/Reporter/JUnitReporter.php b/src/Report/Reporter/JUnitReporter.php index e986615c..c40f6fcd 100644 --- a/src/Report/Reporter/JUnitReporter.php +++ b/src/Report/Reporter/JUnitReporter.php @@ -12,8 +12,12 @@ final class JUnitReporter implements ReporterInterface { public const NAME = 'junit'; - public function display(OutputInterface $output, Report $report, ?string $level = null): void - { + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void { $violations = $report->getViolations($level); $count = \count($violations); @@ -30,7 +34,7 @@ public function display(OutputInterface $output, Report $report, ?string $level $text .= $this->createTestCase( sprintf('%s:%s', $violation->getFilename(), $violation->getLine() ?? 0), strtolower(Violation::getLevelAsString($violation->getLevel())), - $violation->getMessage() + $violation->getDebugMessage($debug) ); } } else { diff --git a/src/Report/Reporter/NullReporter.php b/src/Report/Reporter/NullReporter.php index fbd417d6..5bb8894b 100644 --- a/src/Report/Reporter/NullReporter.php +++ b/src/Report/Reporter/NullReporter.php @@ -14,7 +14,11 @@ final class NullReporter implements ReporterInterface { public const NAME = 'null'; - public function display(OutputInterface $output, Report $report, ?string $level = null): void - { + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void { } } diff --git a/src/Report/Reporter/ReporterInterface.php b/src/Report/Reporter/ReporterInterface.php index 05e719e8..cff3823d 100644 --- a/src/Report/Reporter/ReporterInterface.php +++ b/src/Report/Reporter/ReporterInterface.php @@ -9,5 +9,10 @@ interface ReporterInterface { - public function display(OutputInterface $output, Report $report, ?string $level = null): void; + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void; } diff --git a/src/Report/Reporter/TextReporter.php b/src/Report/Reporter/TextReporter.php index 19898a6e..ec9a8d4e 100644 --- a/src/Report/Reporter/TextReporter.php +++ b/src/Report/Reporter/TextReporter.php @@ -23,8 +23,12 @@ final class TextReporter implements ReporterInterface private const ERROR_LINE_FORMAT = '%-5s| %s'; private const ERROR_LINE_WIDTH = 120; - public function display(OutputInterface $output, Report $report, ?string $level = null): void - { + public function display( + OutputInterface $output, + Report $report, + ?string $level, + bool $debug + ): void { $io = new SymfonyStyle(new ArrayInput([]), $output); if ( @@ -48,7 +52,7 @@ public function display(OutputInterface $output, Report $report, ?string $level $line = $violation->getLine(); if (null === $line || false === $content) { - $formattedText[] = $this->formatErrorMessage($violation); + $formattedText[] = $this->formatErrorMessage($violation, $debug); } else { $lines = $this->getContext($content, $line); foreach ($lines as $no => $code) { @@ -59,7 +63,7 @@ public function display(OutputInterface $output, Report $report, ?string $level ); if ($no === $violation->getLine()) { - $formattedText[] = $this->formatErrorMessage($violation); + $formattedText[] = $this->formatErrorMessage($violation, $debug); } } } @@ -119,12 +123,12 @@ private function getContext(string $template, int $line): array return array_map(fn (string $code): string => substr($code, min($indents)), $result); } - private function formatErrorMessage(Violation $message): string + private function formatErrorMessage(Violation $message, bool $debug): string { return sprintf( sprintf('%s', self::ERROR_LINE_FORMAT), self::ERROR_CURSOR_CHAR, - wordwrap($message->getMessage(), self::ERROR_LINE_WIDTH) + wordwrap($message->getDebugMessage($debug), self::ERROR_LINE_WIDTH) ); } } diff --git a/src/Report/Violation.php b/src/Report/Violation.php index 0b9b7357..c5102e80 100644 --- a/src/Report/Violation.php +++ b/src/Report/Violation.php @@ -20,8 +20,6 @@ public function __construct( private int $level, private string $message, private string $filename, - private ?int $line = null, - private ?int $linePosition = null, private ?string $ruleName = null, private ?ViolationId $identifier = null, ) { @@ -63,9 +61,13 @@ public function getMessage(): string return $this->message; } - public function getLine(): ?int + public function getDebugMessage(bool $debug): string { - return $this->line; + if (!$debug) { + return $this->message; + } + + return $this->identifier?->toString() ?? $this->message; } public function getFilename(): string @@ -73,11 +75,6 @@ public function getFilename(): string return $this->filename; } - public function getLinePosition(): ?int - { - return $this->linePosition; - } - public function getRuleName(): ?string { return $this->ruleName; @@ -87,4 +84,14 @@ public function getIdentifier(): ?ViolationId { return $this->identifier; } + + public function getLine(): ?int + { + return $this->identifier?->getLine(); + } + + public function getLinePosition(): ?int + { + return $this->identifier?->getLinePosition(); + } } diff --git a/src/Report/ViolationId.php b/src/Report/ViolationId.php index 2759802a..a5e6a27e 100644 --- a/src/Report/ViolationId.php +++ b/src/Report/ViolationId.php @@ -7,13 +7,23 @@ final class ViolationId { public function __construct( - private ?string $ruleShortName = null, - private ?string $identifier = null, + private ?string $ruleIdentifier = null, + private ?string $messageIdentifier = null, private ?int $line = null, private ?int $linePosition = null, ) { } + public function getLine(): ?int + { + return $this->line; + } + + public function getLinePosition(): ?int + { + return $this->linePosition; + } + public static function fromString(string $string, ?int $line = null): self { $exploded = explode(':', $string); @@ -35,8 +45,8 @@ public function toString(): string { $name = rtrim(sprintf( '%s.%s', - $this->ruleShortName ?? '', - $this->identifier ?? '', + $this->ruleIdentifier ?? '', + $this->messageIdentifier ?? '', ), '.'); return rtrim(sprintf( @@ -49,8 +59,8 @@ public function toString(): string public function match(self $violationId): bool { - return $this->matchValue($this->ruleShortName, $violationId->ruleShortName) - && $this->matchValue($this->identifier, $violationId->identifier) + return $this->matchValue($this->ruleIdentifier, $violationId->ruleIdentifier) + && $this->matchValue($this->messageIdentifier, $violationId->messageIdentifier) && $this->matchValue($this->line, $violationId->line) && $this->matchValue($this->linePosition, $violationId->linePosition); } diff --git a/src/Rules/AbstractRule.php b/src/Rules/AbstractRule.php index f1e66655..c8b658e8 100644 --- a/src/Rules/AbstractRule.php +++ b/src/Rules/AbstractRule.php @@ -172,10 +172,8 @@ private function addMessage(int $messageType, string $message, Token $token, ?st $messageType, $message, $token->getFilename(), - $token->getLine(), - $token->getPosition(), $this->getName(), - $id + $id, ); $report->addViolation($violation); diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index 6eeeb966..fa786ee7 100644 --- a/src/Runner/Linter.php +++ b/src/Runner/Linter.php @@ -14,6 +14,7 @@ use TwigCsFixer\Exception\CannotTokenizeException; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Violation; +use TwigCsFixer\Report\ViolationId; use TwigCsFixer\Ruleset\Ruleset; use TwigCsFixer\Token\TokenizerInterface; @@ -68,7 +69,8 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = Violation::LEVEL_FATAL, sprintf('File is invalid: %s', $error->getRawMessage()), $filePath, - $error->getTemplateLine() + null, + new ViolationId(line: $error->getTemplateLine()) ); $report->addViolation($violation); diff --git a/tests/Command/TwigCsFixerCommandTest.php b/tests/Command/TwigCsFixerCommandTest.php index 4f38c40c..1709281d 100644 --- a/tests/Command/TwigCsFixerCommandTest.php +++ b/tests/Command/TwigCsFixerCommandTest.php @@ -61,6 +61,28 @@ public function testExecuteWithReportErrors(): void $display = $commandTester->getDisplay(); static::assertStringContainsString('directory/subdirectory/file.twig', $display); static::assertStringContainsString('directory/file.twig', $display); + static::assertStringNotContainsString('DelimiterSpacing.After', $display); + static::assertStringContainsString( + '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 3', + $display + ); + static::assertSame(Command::FAILURE, $commandTester->getStatusCode()); + } + + public function testExecuteWithReportErrorsAndDebug(): void + { + $command = new TwigCsFixerCommand(); + + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'paths' => [$this->getTmpPath(__DIR__.'/Fixtures')], + '--debug' => true, + ]); + + $display = $commandTester->getDisplay(); + static::assertStringContainsString('directory/subdirectory/file.twig', $display); + static::assertStringContainsString('directory/file.twig', $display); + static::assertStringContainsString('DelimiterSpacing.After', $display); static::assertStringContainsString( '[ERROR] Files linted: 3, notices: 0, warnings: 0, errors: 3', $display @@ -152,7 +174,7 @@ public function testExecuteWithError(): void '--config' => $this->getTmpPath(__DIR__.'/Fixtures/.config-not-found.php'), ]); - static::assertStringStartsWith('Error: ', $commandTester->getDisplay()); + static::assertStringStartsWith('Error: Cannot find the config file', $commandTester->getDisplay()); static::assertSame(Command::INVALID, $commandTester->getStatusCode()); } diff --git a/tests/Report/Reporter/CheckstyleReporterTest.php b/tests/Report/Reporter/CheckstyleReporterTest.php index 3bb4c653..6b1aba16 100644 --- a/tests/Report/Reporter/CheckstyleReporterTest.php +++ b/tests/Report/Reporter/CheckstyleReporterTest.php @@ -11,13 +11,14 @@ use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\CheckstyleReporter; use TwigCsFixer\Report\Violation; +use TwigCsFixer\Report\ViolationId; final class CheckstyleReporterTest extends TestCase { /** * @dataProvider displayDataProvider */ - public function testDisplayErrors(string $expected, ?string $level): void + public function testDisplayErrors(string $expected, ?string $level, bool $debug): void { $textFormatter = new CheckstyleReporter(); @@ -26,30 +27,66 @@ public function testDisplayErrors(string $expected, ?string $level): void $file3 = __DIR__.'/Fixtures/file3.twig'; $report = new Report([new SplFileInfo($file), new SplFileInfo($file2), new SplFileInfo($file3)]); - $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeRule'); + $violation0 = new Violation( + Violation::LEVEL_NOTICE, + 'Notice', + $file, + 'NoticeRule', + new ViolationId('NoticeId', null, 1) + ); $report->addViolation($violation0); - $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); + $violation1 = new Violation( + Violation::LEVEL_WARNING, + 'Warning', + $file, + 'WarningRule', + new ViolationId('WarningId', null, 2, 22) + ); $report->addViolation($violation1); - $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); + $violation2 = new Violation( + Violation::LEVEL_ERROR, + 'Error', + $file, + 'ErrorRule', + new ViolationId('ErrorId', null, 3, 33) + ); $report->addViolation($violation2); - $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation( + Violation::LEVEL_FATAL, + 'Fatal', + $file, + null, + new ViolationId('FatalId') + ); $report->addViolation($violation3); - $violation4 = new Violation(Violation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Rule'); + $violation4 = new Violation( + Violation::LEVEL_NOTICE, + 'Notice2', + $file2, + 'Notice2Rule', + new ViolationId('NoticeId', null, 1, 11) + ); $report->addViolation($violation4); - $violation5 = new Violation(Violation::LEVEL_FATAL, '\'"<&>"\'', $file3); + $violation5 = new Violation( + Violation::LEVEL_FATAL, + '\'"<&>"\'', + $file3, + null, + new ViolationId('FatalId') + ); $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report, $level); + $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); static::assertStringContainsString($expected, $text); } /** - * @return iterable + * @return iterable */ public static function displayDataProvider(): iterable { @@ -75,6 +112,7 @@ public static function displayDataProvider(): iterable __DIR__ ), null, + false, ]; yield [ @@ -94,6 +132,27 @@ public static function displayDataProvider(): iterable __DIR__ ), Report::MESSAGE_TYPE_ERROR, + false, + ]; + + yield [ + sprintf( + << + + + + + + + + + + EOD, + __DIR__ + ), + Report::MESSAGE_TYPE_ERROR, + true, ]; } } diff --git a/tests/Report/Reporter/GithubReporterTest.php b/tests/Report/Reporter/GithubReporterTest.php index b31ce34c..8f928cce 100644 --- a/tests/Report/Reporter/GithubReporterTest.php +++ b/tests/Report/Reporter/GithubReporterTest.php @@ -11,44 +11,69 @@ use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\GithubReporter; use TwigCsFixer\Report\Violation; +use TwigCsFixer\Report\ViolationId; final class GithubReporterTest extends TestCase { /** * @dataProvider displayDataProvider */ - public function testDisplayErrors(string $expected, ?string $level): void + public function testDisplayErrors(string $expected, ?string $level, bool $debug): void { $textFormatter = new GithubReporter(); $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeRule'); + $violation0 = new Violation( + Violation::LEVEL_NOTICE, + 'Notice', + $file, + 'Rule', + new ViolationId('NoticeId', null, 1) + ); $report->addViolation($violation0); - $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); + $violation1 = new Violation( + Violation::LEVEL_WARNING, + 'Warning', + $file, + 'Rule', + new ViolationId('WarningId', null, 2, 22) + ); $report->addViolation($violation1); - $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); + $violation2 = new Violation( + Violation::LEVEL_ERROR, + 'Error', + $file, + 'Rule', + new ViolationId('ErrorId', null, 3, 33) + ); $report->addViolation($violation2); - $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal'."\n".'with new line', $file); + $violation3 = new Violation( + Violation::LEVEL_FATAL, + 'Fatal'."\n".'with new line', + $file, + 'Rule', + new ViolationId('FatalId') + ); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report, $level); + $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); static::assertStringContainsString($expected, $text); } /** - * @return iterable + * @return iterable */ public static function displayDataProvider(): iterable { yield [ sprintf( <<addViolation($violation0); - $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); + $violation1 = new Violation( + Violation::LEVEL_WARNING, + 'Warning', + $file, + 'Rule', + new ViolationId('WarningId', null, 2, 22) + ); $report->addViolation($violation1); - $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); + $violation2 = new Violation( + Violation::LEVEL_ERROR, + 'Error', + $file, + 'Rule', + new ViolationId('ErrorId', null, 3, 33) + ); $report->addViolation($violation2); - $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation( + Violation::LEVEL_FATAL, + 'Fatal', + $file, + 'Rule', + new ViolationId('FatalId') + ); $report->addViolation($violation3); - $violation4 = new Violation(Violation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Rule'); + $violation4 = new Violation( + Violation::LEVEL_NOTICE, + 'Notice2', + $file2, + 'Rule', + new ViolationId('NoticeId', null, 1) + ); $report->addViolation($violation4); - $violation5 = new Violation(Violation::LEVEL_FATAL, '\'"<&>"\'', $file3); + $violation5 = new Violation( + Violation::LEVEL_FATAL, + '\'"<&>"\'', + $file3, + 'Rule', + new ViolationId('FatalId') + ); $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report, $level); + $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); static::assertStringContainsString($expected, $text); } /** - * @return iterable + * @return iterable */ public static function displayDataProvider(): iterable { @@ -83,6 +120,39 @@ public static function displayDataProvider(): iterable __DIR__ ), null, + false, + ]; + yield [ + sprintf( + << + + + + + + + + + + + + + + + + + + + + + + + EOD, + __DIR__ + ), + null, + true, ]; } diff --git a/tests/Report/Reporter/NullReporterTest.php b/tests/Report/Reporter/NullReporterTest.php index d6243b98..11c9fa65 100644 --- a/tests/Report/Reporter/NullReporterTest.php +++ b/tests/Report/Reporter/NullReporterTest.php @@ -24,17 +24,17 @@ public function testDisplayErrors(?string $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file); $report->addViolation($violation0); - $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file); $report->addViolation($violation1); - $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file); $report->addViolation($violation2); $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report, $level); + $textFormatter->display($output, $report, $level, false); $text = $output->fetch(); static::assertSame('', $text); diff --git a/tests/Report/Reporter/TextReporterTest.php b/tests/Report/Reporter/TextReporterTest.php index e354bf1d..3c095b6e 100644 --- a/tests/Report/Reporter/TextReporterTest.php +++ b/tests/Report/Reporter/TextReporterTest.php @@ -11,30 +11,55 @@ use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\TextReporter; use TwigCsFixer\Report\Violation; +use TwigCsFixer\Report\ViolationId; final class TextReporterTest extends TestCase { /** * @dataProvider displayDataProvider */ - public function testDisplayErrors(string $expected, ?string $level): void + public function testDisplayErrors(string $expected, ?string $level, bool $debug): void { $textFormatter = new TextReporter(); $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1); + $violation0 = new Violation( + Violation::LEVEL_NOTICE, + 'Notice', + $file, + 'Rule', + new ViolationId('NoticeId', null, 1) + ); $report->addViolation($violation0); - $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2); + $violation1 = new Violation( + Violation::LEVEL_WARNING, + 'Warning', + $file, + 'Rule', + new ViolationId('WarningId', null, 2) + ); $report->addViolation($violation1); - $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); + $violation2 = new Violation( + Violation::LEVEL_ERROR, + 'Error', + $file, + 'Rule', + new ViolationId('ErrorId', null, 3) + ); $report->addViolation($violation2); - $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation( + Violation::LEVEL_FATAL, + 'Fatal', + $file, + 'Rule', + new ViolationId('FatalId') + ); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report, $level); + $textFormatter->display($output, $report, $level, $debug); $text = $output->fetch(); static::assertStringContainsString($expected, $text); @@ -42,7 +67,7 @@ public function testDisplayErrors(string $expected, ?string $level): void } /** - * @return iterable + * @return iterable */ public static function displayDataProvider(): iterable { @@ -71,6 +96,7 @@ public static function displayDataProvider(): iterable __DIR__ ), null, + false, ]; yield [ @@ -89,6 +115,26 @@ public static function displayDataProvider(): iterable __DIR__ ), Report::MESSAGE_TYPE_ERROR, + false, + ]; + + yield [ + sprintf( + <<> | ErrorId:3\e[39m + 4 | + ------- ----------------------------------- + \e[33mFATAL\e[39m \e[31m>> | FatalId\e[39m + ------- ----------------------------------- + EOD, + __DIR__ + ), + Report::MESSAGE_TYPE_ERROR, + true, ]; } @@ -100,7 +146,7 @@ public function testDisplaySuccess(): void $report = new Report([new SplFileInfo($file)]); $output = new BufferedOutput(); - $textFormatter->display($output, $report); + $textFormatter->display($output, $report, null, false); $text = $output->fetch(); static::assertStringNotContainsString(sprintf('KO %s/Fixtures/file.twig', __DIR__), $text); @@ -115,11 +161,11 @@ public function testDisplayMultipleFiles(): void $file2 = __DIR__.'/Fixtures/file2.twig'; $report = new Report([new SplFileInfo($file), new SplFileInfo($file2)]); - $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); + $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, null, new ViolationId(line: 3)); $report->addViolation($violation); $output = new BufferedOutput(); - $textFormatter->display($output, $report); + $textFormatter->display($output, $report, null, false); static::assertStringContainsString( sprintf( @@ -147,11 +193,11 @@ public function testDisplayNotFoundFile(): void $file = __DIR__.'/Fixtures/fileNotFound.twig'; $report = new Report([new SplFileInfo($file)]); - $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 1); + $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, null, new ViolationId(line: 1)); $report->addViolation($violation); $output = new BufferedOutput(); - $textFormatter->display($output, $report); + $textFormatter->display($output, $report, null, false); static::assertStringContainsString( sprintf( @@ -177,11 +223,11 @@ public function testDisplayBlock(string $expected, int $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation = new Violation($level, 'Message', $file, 1); + $violation = new Violation($level, 'Message', $file, null, new ViolationId(line: 1)); $report->addViolation($violation); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); - $textFormatter->display($output, $report); + $textFormatter->display($output, $report, null, false); $text = $output->fetch(); static::assertStringContainsString($expected, $text); diff --git a/tests/Report/ViolationTest.php b/tests/Report/ViolationTest.php index c4557f33..e6c14a8b 100644 --- a/tests/Report/ViolationTest.php +++ b/tests/Report/ViolationTest.php @@ -12,8 +12,8 @@ final class ViolationTest extends TestCase { public function testGetters(): void { - $violationId = new ViolationId('name'); - $violation = new Violation(Violation::LEVEL_WARNING, 'message', 'filename', 42, 33, 'name', $violationId); + $violationId = new ViolationId('nameId', null, 42, 33); + $violation = new Violation(Violation::LEVEL_WARNING, 'message', 'filename', 'name', $violationId); static::assertSame(Violation::LEVEL_WARNING, $violation->getLevel()); static::assertSame('message', $violation->getMessage());