Skip to content

Commit a8c1688

Browse files
authored
Order of multiple asserts do not matter (#15)
1 parent 6e336f8 commit a8c1688

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/RuleTestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ protected function analyzeFiles(
6464
$actualErrors = $this->processActualErrors(array_values($fileErrors));
6565
$expectedErrors = $this->parseExpectedErrors($file);
6666

67+
sort($actualErrors);
68+
sort($expectedErrors);
69+
6770
$extraErrors = array_filter($actualErrors, static fn (string $error): bool => !in_array($error, $expectedErrors, true));
6871
$missingErrors = array_filter($expectedErrors, static fn (string $error): bool => !in_array($error, $actualErrors, true));
6972

tests/Rule/Data/DisallowDivisionByLiteralZeroRule/DisallowDivisionByLiteralZeroRule.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node;
66
use PhpParser\Node\Expr\BinaryOp\Div;
7+
use PhpParser\Node\Scalar\Float_;
78
use PhpParser\Node\Scalar\Int_;
89
use PHPStan\Analyser\Scope;
910
use PHPStan\Rules\Rule;
@@ -30,6 +31,14 @@ public function processNode(Node $node, Scope $scope): array
3031
];
3132
}
3233

34+
if ($node->right instanceof Float_ && $node->right->value === 0.) {
35+
return [
36+
RuleErrorBuilder::message('Division by float zero is not allowed')
37+
->identifier('shipmonk.divisionByFloatZero')
38+
->build(),
39+
];
40+
}
41+
3342
return [];
3443
}
3544

tests/Rule/Data/DisallowDivisionByLiteralZeroRule/multiple-errors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ function testMultipleErrorsPerLine(): void
1717

1818
// Mixed valid and invalid operations (only invalid ones should error)
1919
$mixed = ($a / 2) + (5 / 0) + ($a / 3) + (10 / 0); // error: Division by literal zero is not allowed // error: Division by literal zero is not allowed
20+
21+
// Order does not matter
22+
(1 / 0) + (5 / 0.); // error: Division by float zero is not allowed // error: Division by literal zero is not allowed
23+
(1 / 0) + (5 / 0.); // error: Division by literal zero is not allowed // error: Division by float zero is not allowed
2024
}
2125

0 commit comments

Comments
 (0)