diff --git a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php index 47834ddd43..6c24d4fc77 100644 --- a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php @@ -63,4 +63,14 @@ public function testBug3264(): void $this->analyse([__DIR__ . '/data/bug-3264.php'], []); } + public function testBug5656(): void + { + $this->analyse([__DIR__ . '/data/bug-5656.php'], []); + } + + public function testBug3867(): void + { + $this->analyse([__DIR__ . '/data/bug-3867.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index 261ceae50b..6b3ad7be53 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -488,4 +488,15 @@ public function testBug3366(): void $this->analyse([__DIR__ . '/data/bug-3366.php'], []); } + public function testBug5362(): void + { + $this->checkAlwaysTrueStrictComparison = true; + $this->analyse([__DIR__ . '/data/bug-5362.php'], [ + [ + 'Strict comparison using === between 0 and 1|2 will always evaluate to false.', + 23, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-3867.php b/tests/PHPStan/Rules/Comparison/data/bug-3867.php new file mode 100644 index 0000000000..46bf02e5f4 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-3867.php @@ -0,0 +1,24 @@ +$method(); + + if (!empty($result)) { + break; + } + } while (count($try) > 0); + } +} diff --git a/tests/PHPStan/Rules/Comparison/data/bug-5362.php b/tests/PHPStan/Rules/Comparison/data/bug-5362.php new file mode 100644 index 0000000000..51284284ca --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-5362.php @@ -0,0 +1,32 @@ +doFoo($retry); + + break; + } catch (\Exception $e) { + if (0 === $retry) { + throw $e; + } + + --$retry; + } + } while ($retry > 0); + } + +} diff --git a/tests/PHPStan/Rules/Comparison/data/bug-5656.php b/tests/PHPStan/Rules/Comparison/data/bug-5656.php new file mode 100644 index 0000000000..aca016dfbb --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-5656.php @@ -0,0 +1,41 @@ + 10) { + $i = 1; + } + $control += $i * $v; + ++$i; + } + + $control %= 11; + + if (10 !== $control) { + break; + } + } + + if (10 === $control) { + $control = 0; + } + + return $expected === $control; +} + +$values = [0, 1, 0, 6, 0, 6, 2, 3, 1, 5]; +okpoValidate($values);