diff --git a/composer.json b/composer.json index 355c9d4..6754002 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,10 @@ "autoload-dev": { "psr-4": { "ShipMonkTests\\PHPStanDev\\": "tests/" - } + }, + "classmap": [ + "tests/Rule/Data" + ] }, "config": { "allow-plugins": { diff --git a/src/RuleTestCase.php b/src/RuleTestCase.php index baed3fc..58af31e 100644 --- a/src/RuleTestCase.php +++ b/src/RuleTestCase.php @@ -39,7 +39,7 @@ protected function analyzeFiles(array $files, bool $autofix = false): void if ($autofix) { foreach ($files as $file) { - $fileErrors = array_filter($analyserErrors, static fn(Error $error): bool => $error->getFile() === $file); + $fileErrors = array_filter($analyserErrors, static fn(Error $error): bool => $error->getFilePath() === $file); $this->autofix($file, array_values($fileErrors)); } @@ -48,7 +48,7 @@ protected function analyzeFiles(array $files, bool $autofix = false): void } foreach ($files as $file) { - $fileErrors = array_filter($analyserErrors, static fn(Error $error): bool => $error->getFile() === $file); + $fileErrors = array_filter($analyserErrors, static fn(Error $error): bool => $error->getFilePath() === $file); $actualErrors = $this->processActualErrors(array_values($fileErrors)); $expectedErrors = $this->parseExpectedErrors($file); diff --git a/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/trait.php b/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/trait.php new file mode 100644 index 0000000..f9e6da1 --- /dev/null +++ b/tests/Rule/Data/DisallowDivisionByLiteralZeroRule/trait.php @@ -0,0 +1,15 @@ +analyzeFiles([__DIR__ . '/Rule/Data/DisallowDivisionByLiteralZeroRule/code.php']); } + public function testTrait(): void + { + $this->analyzeFiles([__DIR__ . '/Rule/Data/DisallowDivisionByLiteralZeroRule/trait.php']); + } + public function testMultipleErrorsOnSameLine(): void { // Create a dedicated test file for multiple errors demonstration