diff --git a/src/Report/Report.php b/src/Report/Report.php index 97ed633a..e59c7558 100644 --- a/src/Report/Report.php +++ b/src/Report/Report.php @@ -20,7 +20,7 @@ final class Report /** * @var array> */ - private array $messagesByFiles = []; + private array $violationsByFile = []; /** * @var array @@ -39,14 +39,14 @@ final class Report public function __construct(iterable $files) { foreach ($files as $file) { - $this->messagesByFiles[$file->getPathname()] = []; + $this->violationsByFile[$file->getPathname()] = []; } } - public function addMessage(SniffViolation $sniffViolation): self + public function addViolation(SniffViolation $sniffViolation): self { $filename = $sniffViolation->getFilename(); - if (!isset($this->messagesByFiles[$filename])) { + if (!isset($this->violationsByFile[$filename])) { throw new InvalidArgumentException( sprintf('The file "%s" is not handled by this report.', $filename) ); @@ -66,7 +66,7 @@ public function addMessage(SniffViolation $sniffViolation): self break; } - $this->messagesByFiles[$filename][] = $sniffViolation; + $this->violationsByFile[$filename][] = $sniffViolation; return $this; } @@ -74,21 +74,21 @@ public function addMessage(SniffViolation $sniffViolation): self /** * @return list */ - public function getMessages(string $filename, ?string $level = null): array + public function getFileViolations(string $filename, ?string $level = null): array { - if (!isset($this->messagesByFiles[$filename])) { + if (!isset($this->violationsByFile[$filename])) { throw new InvalidArgumentException( sprintf('The file "%s" is not handled by this report.', $filename) ); } if (null === $level) { - return $this->messagesByFiles[$filename]; + return $this->violationsByFile[$filename]; } return array_values( array_filter( - $this->messagesByFiles[$filename], + $this->violationsByFile[$filename], static fn (SniffViolation $message): bool => $message->getLevel() >= SniffViolation::getLevelAsInt($level) ) ); @@ -97,9 +97,9 @@ public function getMessages(string $filename, ?string $level = null): array /** * @return list */ - public function getAllMessages(?string $level = null): array + public function getViolations(?string $level = null): array { - $messages = array_merge(...array_values($this->messagesByFiles)); + $messages = array_merge(...array_values($this->violationsByFile)); if (null === $level) { return $messages; @@ -118,17 +118,17 @@ public function getAllMessages(?string $level = null): array */ public function getFiles(): array { - return array_keys($this->messagesByFiles); + return array_keys($this->violationsByFile); } public function getTotalFiles(): int { - return \count($this->messagesByFiles); + return \count($this->violationsByFile); } public function addFixedFile(string $filename): self { - if (!isset($this->messagesByFiles[$filename])) { + if (!isset($this->violationsByFile[$filename])) { throw new InvalidArgumentException( sprintf('The file "%s" is not handled by this report.', $filename) ); diff --git a/src/Report/Reporter/CheckstyleReporter.php b/src/Report/Reporter/CheckstyleReporter.php index 01adc635..ef114b14 100644 --- a/src/Report/Reporter/CheckstyleReporter.php +++ b/src/Report/Reporter/CheckstyleReporter.php @@ -19,16 +19,16 @@ public function display(OutputInterface $output, Report $report, ?string $level $text .= ''."\n"; foreach ($report->getFiles() as $file) { - $fileMessages = $report->getMessages($file, $level); - if (0 === \count($fileMessages)) { + $fileViolations = $report->getFileViolations($file, $level); + if (0 === \count($fileViolations)) { continue; } $text .= sprintf(' ', $this->xmlEncode($file))."\n"; - foreach ($fileMessages as $message) { - $line = (string) $message->getLine(); - $linePosition = (string) $message->getLinePosition(); - $sniffName = $message->getSniffName(); + foreach ($fileViolations as $violation) { + $line = (string) $violation->getLine(); + $linePosition = (string) $violation->getLinePosition(); + $sniffName = $violation->getSniffName(); $text .= ' getLevel())).'"'; - $text .= ' message="'.$this->xmlEncode($message->getMessage()).'"'; + $text .= ' severity="'.strtolower(SniffViolation::getLevelAsString($violation->getLevel())).'"'; + $text .= ' message="'.$this->xmlEncode($violation->getMessage()).'"'; if (null !== $sniffName) { $text .= ' source="'.$sniffName.'"'; } diff --git a/src/Report/Reporter/GithubReporter.php b/src/Report/Reporter/GithubReporter.php new file mode 100644 index 00000000..f6f00bf2 --- /dev/null +++ b/src/Report/Reporter/GithubReporter.php @@ -0,0 +1,48 @@ +getViolations($level); + foreach ($violations as $violation) { + $text = match ($violation->getLevel()) { + SniffViolation::LEVEL_NOTICE => '::notice', + SniffViolation::LEVEL_WARNING => '::warning', + default => '::error', + }; + + $text .= ' file='.$violation->getFilename(); + + $line = (string) $violation->getLine(); + if ('' !== $line) { + $text .= ',line='.$line; + } + $linePosition = (string) $violation->getLinePosition(); + if ('' !== $linePosition) { + $text .= ',col='.$linePosition; + } + + // newlines need to be encoded + // see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448 + $text .= '::'.str_replace("\n", '%0A', $violation->getMessage()); + + $output->writeln($text); + } + } +} diff --git a/src/Report/Reporter/JUnitReporter.php b/src/Report/Reporter/JUnitReporter.php index 43e0608a..c3a7eb0f 100644 --- a/src/Report/Reporter/JUnitReporter.php +++ b/src/Report/Reporter/JUnitReporter.php @@ -14,23 +14,23 @@ final class JUnitReporter implements ReporterInterface public function display(OutputInterface $output, Report $report, ?string $level = null): void { - $messages = $report->getAllMessages($level); - $totalErrors = \count($messages); + $violations = $report->getViolations($level); + $count = \count($violations); $text = ''."\n"; $text .= ''."\n"; $text .= ' '.sprintf( '', - max($totalErrors, 1), - $totalErrors + max($count, 1), + $count )."\n"; - if ($totalErrors > 0) { - foreach ($messages as $message) { + if ($count > 0) { + foreach ($violations as $violation) { $text .= $this->createTestCase( - sprintf('%s:%s', $message->getFilename(), $message->getLine() ?? 0), - strtolower(SniffViolation::getLevelAsString($message->getLevel())), - $message->getMessage() + sprintf('%s:%s', $violation->getFilename(), $violation->getLine() ?? 0), + strtolower(SniffViolation::getLevelAsString($violation->getLevel())), + $violation->getMessage() ); } } else { diff --git a/src/Report/Reporter/TextReporter.php b/src/Report/Reporter/TextReporter.php index 9f00308a..94889e49 100644 --- a/src/Report/Reporter/TextReporter.php +++ b/src/Report/Reporter/TextReporter.php @@ -36,19 +36,19 @@ public function display(OutputInterface $output, Report $report, ?string $level } foreach ($report->getFiles() as $file) { - $fileMessages = $report->getMessages($file, $level); - if (\count($fileMessages) > 0) { + $fileViolations = $report->getFileViolations($file, $level); + if (\count($fileViolations) > 0) { $io->text(sprintf('KO %s', $file)); } $content = @file_get_contents($file); $rows = []; - foreach ($fileMessages as $message) { + foreach ($fileViolations as $violation) { $formattedText = []; - $line = $message->getLine(); + $line = $violation->getLine(); if (null === $line || false === $content) { - $formattedText[] = $this->formatErrorMessage($message); + $formattedText[] = $this->formatErrorMessage($violation); } else { $lines = $this->getContext($content, $line); foreach ($lines as $no => $code) { @@ -58,8 +58,8 @@ public function display(OutputInterface $output, Report $report, ?string $level wordwrap($code, self::ERROR_LINE_WIDTH) ); - if ($no === $message->getLine()) { - $formattedText[] = $this->formatErrorMessage($message); + if ($no === $violation->getLine()) { + $formattedText[] = $this->formatErrorMessage($violation); } } } @@ -68,7 +68,7 @@ public function display(OutputInterface $output, Report $report, ?string $level $rows[] = new TableSeparator(); } - $messageLevel = SniffViolation::getLevelAsString($message->getLevel()); + $messageLevel = SniffViolation::getLevelAsString($violation->getLevel()); $rows[] = [ new TableCell(sprintf('%s', $messageLevel)), implode("\n", $formattedText), diff --git a/src/Report/ReporterFactory.php b/src/Report/ReporterFactory.php index 8d2a2253..fa5591bc 100644 --- a/src/Report/ReporterFactory.php +++ b/src/Report/ReporterFactory.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use TwigCsFixer\Report\Reporter\CheckstyleReporter; +use TwigCsFixer\Report\Reporter\GithubReporter; use TwigCsFixer\Report\Reporter\JUnitReporter; use TwigCsFixer\Report\Reporter\NullReporter; use TwigCsFixer\Report\Reporter\ReporterInterface; @@ -20,6 +21,7 @@ public function getReporter(string $format = TextReporter::NAME): ReporterInterf TextReporter::NAME => new TextReporter(), CheckstyleReporter::NAME => new CheckstyleReporter(), JUnitReporter::NAME => new JUnitReporter(), + GithubReporter::NAME => new GithubReporter(), default => throw new InvalidArgumentException( sprintf('No reporter supports the format "%s".', $format) ), diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index a691bc8b..2f786b20 100644 --- a/src/Runner/Linter.php +++ b/src/Runner/Linter.php @@ -51,7 +51,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $filePath ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); continue; } @@ -71,7 +71,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $error->getTemplateLine() ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); continue; } @@ -91,7 +91,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $filePath ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); continue; } catch (CannotFixFileException $exception) { $sniffViolation = new SniffViolation( @@ -100,7 +100,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $filePath ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); } } @@ -116,7 +116,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $filePath ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); continue; } restore_error_handler(); @@ -129,7 +129,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = // Only cache the file if there is no error in order to // - still see the errors when running again the linter // - still having the possibility to fix the file - if ([] === $report->getMessages($filePath)) { + if ([] === $report->getFileViolations($filePath)) { $this->cacheManager->setFile($filePath, $content); } } @@ -146,7 +146,7 @@ private function setErrorHandler(Report $report, string $file): void $file ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); return true; }, \E_USER_DEPRECATED); diff --git a/src/Sniff/AbstractSniff.php b/src/Sniff/AbstractSniff.php index 4de6a80d..016fbad9 100644 --- a/src/Sniff/AbstractSniff.php +++ b/src/Sniff/AbstractSniff.php @@ -143,7 +143,7 @@ private function addMessage(int $messageType, string $message, Token $token): vo $this->getName(), ); - $report->addMessage($sniffViolation); + $report->addViolation($sniffViolation); } private function addFixableMessage(int $messageType, string $message, Token $token): ?FixerInterface diff --git a/tests/Report/ReportTest.php b/tests/Report/ReportTest.php index d8d74b76..21856c03 100644 --- a/tests/Report/ReportTest.php +++ b/tests/Report/ReportTest.php @@ -42,13 +42,13 @@ public function testReport(): void $sniffViolation6 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file3); $sniffViolation7 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - $report->addMessage($sniffViolation1); - $report->addMessage($sniffViolation2); - $report->addMessage($sniffViolation3); - $report->addMessage($sniffViolation4); - $report->addMessage($sniffViolation5); - $report->addMessage($sniffViolation6); - $report->addMessage($sniffViolation7); + $report->addViolation($sniffViolation1); + $report->addViolation($sniffViolation2); + $report->addViolation($sniffViolation3); + $report->addViolation($sniffViolation4); + $report->addViolation($sniffViolation5); + $report->addViolation($sniffViolation6); + $report->addViolation($sniffViolation7); static::assertSame(1, $report->getTotalNotices()); static::assertSame(2, $report->getTotalWarnings()); @@ -58,15 +58,15 @@ public function testReport(): void static::assertSame( [$sniffViolation1, $sniffViolation2, $sniffViolation4, $sniffViolation7], - $report->getMessages($file) + $report->getFileViolations($file) ); static::assertSame( [$sniffViolation3, $sniffViolation5], - $report->getMessages($file2) + $report->getFileViolations($file2) ); static::assertSame( [$sniffViolation6], - $report->getMessages($file3) + $report->getFileViolations($file3) ); static::assertSame( @@ -79,20 +79,20 @@ public function testReport(): void $sniffViolation5, $sniffViolation6, ], - $report->getAllMessages() + $report->getViolations() ); static::assertSame( [$sniffViolation4, $sniffViolation7], - $report->getMessages($file, Report::MESSAGE_TYPE_ERROR) + $report->getFileViolations($file, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( [$sniffViolation5], - $report->getMessages($file2, Report::MESSAGE_TYPE_ERROR) + $report->getFileViolations($file2, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( [$sniffViolation6], - $report->getMessages($file3, Report::MESSAGE_TYPE_ERROR) + $report->getFileViolations($file3, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( [ @@ -101,24 +101,24 @@ public function testReport(): void $sniffViolation5, $sniffViolation6, ], - $report->getAllMessages(Report::MESSAGE_TYPE_ERROR) + $report->getViolations(Report::MESSAGE_TYPE_ERROR) ); } - public function testAddMessageForAnotherFile(): void + public function testAddViolationForAnotherFile(): void { $report = new Report([new SplFileInfo('file.twig')]); $this->expectExceptionMessage('The file "another_file.twig" is not handled by this report.'); - $report->addMessage(new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Message', 'another_file.twig')); + $report->addViolation(new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Message', 'another_file.twig')); } - public function testGetMessageForAnotherFile(): void + public function testGetViolationForAnotherFile(): void { $report = new Report([new SplFileInfo('file.twig')]); $this->expectExceptionMessage('The file "another_file.twig" is not handled by this report.'); - $report->getMessages('another_file.twig'); + $report->getFileViolations('another_file.twig'); } public function testAddFixedFile(): void diff --git a/tests/Report/Formatter/CheckstyleReporterTest.php b/tests/Report/Reporter/CheckstyleReporterTest.php similarity index 92% rename from tests/Report/Formatter/CheckstyleReporterTest.php rename to tests/Report/Reporter/CheckstyleReporterTest.php index d6a52a43..c6d7a2fd 100644 --- a/tests/Report/Formatter/CheckstyleReporterTest.php +++ b/tests/Report/Reporter/CheckstyleReporterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Report\Formatter; +namespace TwigCsFixer\Tests\Report\Reporter; use PHPUnit\Framework\TestCase; use SplFileInfo; @@ -27,19 +27,19 @@ public function testDisplayErrors(string $expected, ?string $level): void $report = new Report([new SplFileInfo($file), new SplFileInfo($file2), new SplFileInfo($file3)]); $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeSniff'); - $report->addMessage($violation0); + $report->addViolation($violation0); $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); - $report->addMessage($violation1); + $report->addViolation($violation1); $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); - $report->addMessage($violation2); + $report->addViolation($violation2); $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - $report->addMessage($violation3); + $report->addViolation($violation3); $violation4 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Sniff'); - $report->addMessage($violation4); + $report->addViolation($violation4); $violation5 = new SniffViolation(SniffViolation::LEVEL_FATAL, '\'"<&>"\'', $file3); - $report->addMessage($violation5); + $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); $textFormatter->display($output, $report, $level); diff --git a/tests/Report/Formatter/Fixtures/file.twig b/tests/Report/Reporter/Fixtures/file.twig similarity index 100% rename from tests/Report/Formatter/Fixtures/file.twig rename to tests/Report/Reporter/Fixtures/file.twig diff --git a/tests/Report/Formatter/Fixtures/file2.twig b/tests/Report/Reporter/Fixtures/file2.twig similarity index 100% rename from tests/Report/Formatter/Fixtures/file2.twig rename to tests/Report/Reporter/Fixtures/file2.twig diff --git a/tests/Report/Reporter/GithubReporterTest.php b/tests/Report/Reporter/GithubReporterTest.php new file mode 100644 index 00000000..ab5b5d29 --- /dev/null +++ b/tests/Report/Reporter/GithubReporterTest.php @@ -0,0 +1,61 @@ +addViolation($violation0); + $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); + $report->addViolation($violation1); + $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); + $report->addViolation($violation2); + $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal'."\n".'with new line', $file); + $report->addViolation($violation3); + + $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); + $textFormatter->display($output, $report, $level); + + $text = $output->fetch(); + static::assertStringContainsString($expected, $text); + } + + /** + * @return iterable + */ + public static function displayDataProvider(): iterable + { + yield [ + sprintf( + <<addMessage($violation0); + $report->addViolation($violation0); $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); - $report->addMessage($violation1); + $report->addViolation($violation1); $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); - $report->addMessage($violation2); + $report->addViolation($violation2); $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - $report->addMessage($violation3); + $report->addViolation($violation3); $violation4 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Sniff'); - $report->addMessage($violation4); + $report->addViolation($violation4); $violation5 = new SniffViolation(SniffViolation::LEVEL_FATAL, '\'"<&>"\'', $file3); - $report->addMessage($violation5); + $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); $textFormatter->display($output, $report, $level); diff --git a/tests/Report/Formatter/NullReporterTest.php b/tests/Report/Reporter/NullReporterTest.php similarity index 87% rename from tests/Report/Formatter/NullReporterTest.php rename to tests/Report/Reporter/NullReporterTest.php index 79aff3e9..eaf39877 100644 --- a/tests/Report/Formatter/NullReporterTest.php +++ b/tests/Report/Reporter/NullReporterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Report\Formatter; +namespace TwigCsFixer\Tests\Report\Reporter; use PHPUnit\Framework\TestCase; use SplFileInfo; @@ -25,13 +25,13 @@ public function testDisplayErrors(?string $level): void $report = new Report([new SplFileInfo($file)]); $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1); - $report->addMessage($violation0); + $report->addViolation($violation0); $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2); - $report->addMessage($violation1); + $report->addViolation($violation1); $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); - $report->addMessage($violation2); + $report->addViolation($violation2); $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - $report->addMessage($violation3); + $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); $textFormatter->display($output, $report, $level); diff --git a/tests/Report/Formatter/TextReporterTest.php b/tests/Report/Reporter/TextReporterTest.php similarity index 95% rename from tests/Report/Formatter/TextReporterTest.php rename to tests/Report/Reporter/TextReporterTest.php index 307996d1..d5ed2411 100644 --- a/tests/Report/Formatter/TextReporterTest.php +++ b/tests/Report/Reporter/TextReporterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Report\Formatter; +namespace TwigCsFixer\Tests\Report\Reporter; use PHPUnit\Framework\TestCase; use SplFileInfo; @@ -25,13 +25,13 @@ public function testDisplayErrors(string $expected, ?string $level): void $report = new Report([new SplFileInfo($file)]); $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1); - $report->addMessage($violation0); + $report->addViolation($violation0); $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2); - $report->addMessage($violation1); + $report->addViolation($violation1); $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); - $report->addMessage($violation2); + $report->addViolation($violation2); $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - $report->addMessage($violation3); + $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); $textFormatter->display($output, $report, $level); @@ -116,7 +116,7 @@ public function testDisplayMultipleFiles(): void $report = new Report([new SplFileInfo($file), new SplFileInfo($file2)]); $violation = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); - $report->addMessage($violation); + $report->addViolation($violation); $output = new BufferedOutput(); $textFormatter->display($output, $report); @@ -148,7 +148,7 @@ public function testDisplayNotFoundFile(): void $report = new Report([new SplFileInfo($file)]); $violation = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 1); - $report->addMessage($violation); + $report->addViolation($violation); $output = new BufferedOutput(); $textFormatter->display($output, $report); @@ -178,7 +178,7 @@ public function testDisplayBlock(string $expected, int $level): void $report = new Report([new SplFileInfo($file)]); $violation = new SniffViolation($level, 'Message', $file, 1); - $report->addMessage($violation); + $report->addViolation($violation); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); $textFormatter->display($output, $report); diff --git a/tests/Runner/LinterTest.php b/tests/Runner/LinterTest.php index b3776849..2846b254 100644 --- a/tests/Runner/LinterTest.php +++ b/tests/Runner/LinterTest.php @@ -46,7 +46,7 @@ public function testUnreadableFilesAreReported(): void $ruleset, ); - $messages = $report->getMessages($fileNotReadablePath); + $messages = $report->getFileViolations($fileNotReadablePath); static::assertCount(1, $messages); $message = $messages[0]; @@ -54,7 +54,7 @@ public function testUnreadableFilesAreReported(): void static::assertSame(SniffViolation::LEVEL_FATAL, $message->getLevel()); static::assertSame($fileNotReadablePath, $message->getFilename()); - static::assertCount(0, $report->getMessages($filePath)); + static::assertCount(0, $report->getFileViolations($filePath)); } public function testInvalidFilesAreReported(): void @@ -70,7 +70,7 @@ public function testInvalidFilesAreReported(): void $linter = new Linter($env, $tokenizer); $report = $linter->run([new SplFileInfo($filePath), new SplFileInfo($filePath2)], $ruleset); - $messages = $report->getMessages($filePath); + $messages = $report->getFileViolations($filePath); static::assertCount(1, $messages); $message = $messages[0]; @@ -79,7 +79,7 @@ public function testInvalidFilesAreReported(): void static::assertSame($filePath, $message->getFilename()); // We still validate other files - $messages = $report->getMessages($filePath2); + $messages = $report->getFileViolations($filePath2); static::assertCount(1, $messages); } @@ -115,7 +115,7 @@ static function () use (&$call): array { $ruleset ); - $messages = $report->getMessages($filePath); + $messages = $report->getFileViolations($filePath); static::assertCount(1, $messages); $message = $messages[0]; @@ -154,7 +154,7 @@ public function testUserDeprecationAreReported(): void static::assertSame(1, $deprecations); restore_error_handler(); - $messages = $report->getMessages($filePath); + $messages = $report->getFileViolations($filePath); static::assertCount(1, $messages); $message = $messages[0]; @@ -219,7 +219,7 @@ static function () use (&$call, $exception): string { $fixer ); - $messages = $report->getMessages($filePath); + $messages = $report->getFileViolations($filePath); static::assertCount(1, $messages); $message = $messages[0]; diff --git a/tests/Sniff/AbstractSniffTestCase.php b/tests/Sniff/AbstractSniffTestCase.php index cde47cca..7843b0bf 100644 --- a/tests/Sniff/AbstractSniffTestCase.php +++ b/tests/Sniff/AbstractSniffTestCase.php @@ -49,7 +49,7 @@ protected function checkSniff( } } - $messages = $report->getMessages($filePath); + $messages = $report->getFileViolations($filePath); /** @var array> $messagePositions */ $messagePositions = [];