From d4557a6fd801747811a6fd46a88259c1a57439a3 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 13 Jan 2022 12:18:22 +0100 Subject: [PATCH] Regression tests Closes https://github.com/phpstan/phpstan/issues/5656 Closes https://github.com/phpstan/phpstan/issues/5362 Closes https://github.com/phpstan/phpstan/issues/3867 --- ...isonOperatorsConstantConditionRuleTest.php | 10 +++++ ...rictComparisonOfDifferentTypesRuleTest.php | 11 +++++ .../Rules/Comparison/data/bug-3867.php | 24 +++++++++++ .../Rules/Comparison/data/bug-5362.php | 32 +++++++++++++++ .../Rules/Comparison/data/bug-5656.php | 41 +++++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-3867.php create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-5362.php create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-5656.php 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);