Skip to content

Commit 2eaa920

Browse files
committed
RuleTestCase: improve main assert error message
1 parent d5b110c commit 2eaa920

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/RuleTestCase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function file_get_contents;
1515
use function file_put_contents;
1616
use function implode;
17+
use function in_array;
1718
use function ksort;
1819
use function preg_match;
1920
use function preg_match_all;
@@ -62,10 +63,15 @@ protected function analyzeFiles(
6263
$actualErrors = $this->processActualErrors(array_values($fileErrors));
6364
$expectedErrors = $this->parseExpectedErrors($file);
6465

66+
$extraErrors = array_filter($actualErrors, static fn (string $error): bool => !in_array($error, $expectedErrors, true));
67+
$missingErrors = array_filter($expectedErrors, static fn (string $error): bool => !in_array($error, $actualErrors, true));
68+
6569
self::assertSame(
6670
implode("\n", $expectedErrors) . "\n",
6771
implode("\n", $actualErrors) . "\n",
68-
"Errors in file {$file} do not match",
72+
"Errors in file {$file} do not match:\n\n" .
73+
($extraErrors === [] ? '' : "New errors reported:\n" . implode("\n", $extraErrors) . "\n\n") .
74+
($missingErrors === [] ? '' : "Errors not reported:\n" . implode("\n", $missingErrors) . "\n\n"),
6975
);
7076
}
7177
}

0 commit comments

Comments
 (0)