diff --git a/src/RuleTestCase.php b/src/RuleTestCase.php index 14b93e6..f2b79b2 100644 --- a/src/RuleTestCase.php +++ b/src/RuleTestCase.php @@ -14,6 +14,7 @@ use function file_get_contents; use function file_put_contents; use function implode; +use function in_array; use function ksort; use function preg_match; use function preg_match_all; @@ -62,10 +63,15 @@ protected function analyzeFiles( $actualErrors = $this->processActualErrors(array_values($fileErrors)); $expectedErrors = $this->parseExpectedErrors($file); + $extraErrors = array_filter($actualErrors, static fn (string $error): bool => !in_array($error, $expectedErrors, true)); + $missingErrors = array_filter($expectedErrors, static fn (string $error): bool => !in_array($error, $actualErrors, true)); + self::assertSame( implode("\n", $expectedErrors) . "\n", implode("\n", $actualErrors) . "\n", - "Errors in file {$file} do not match", + "Errors in file {$file} do not match:\n\n" . + ($extraErrors === [] ? '' : "New errors reported:\n" . implode("\n", $extraErrors) . "\n\n") . + ($missingErrors === [] ? '' : "Errors not reported:\n" . implode("\n", $missingErrors) . "\n\n"), ); } } diff --git a/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/error-message.php b/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/error-message.php new file mode 100644 index 0000000..59ee6fd --- /dev/null +++ b/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/error-message.php @@ -0,0 +1,10 @@ +analyzeFiles([$testFile]); + self::fail('Expected assertion to fail'); + } catch (AssertionFailedError $e) { // @phpstan-ignore catch.internalClass + $expectedMessage = <<getMessage()); + } + } + }