Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"autoload-dev": {
"psr-4": {
"ShipMonkTests\\PHPStanDev\\": "tests/"
}
},
"classmap": [
"tests/Rule/Data"
]
},
"config": {
"allow-plugins": {
Expand Down
4 changes: 2 additions & 2 deletions src/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions tests/Rule/Data/DisallowDivisionByLiteralZeroRule/trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace DisallowDivisionByLiteralZeroRule;

trait MyTrait
{
public function emitError(): float
{
return 10 / 0; // error: Division by literal zero is not allowed
}
}

class TraitUser {
use MyTrait;
}
5 changes: 5 additions & 0 deletions tests/RuleTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public function testRule(): void
$this->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
Expand Down