From ac100bc817475e9071979667a05e464738674daf Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 4 Dec 2022 15:50:35 +0100 Subject: [PATCH] add more non-trait tests --- ...rictComparisonOfDifferentTypesRuleTest.php | 23 +++++++++++- .../Rules/Comparison/data/bug-3633.php | 35 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index b0e28ebe8cb..06eec212c37 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -616,7 +616,28 @@ public function testPhpUnitIntegration(): void public function testBug3633(): void { $this->checkAlwaysTrueStrictComparison = true; - $this->analyse([__DIR__ . '/data/bug-3633.php'], []); + $this->analyse([__DIR__ . '/data/bug-3633.php'], [ + [ + 'Strict comparison using === between class-string and \'Bug3633\\\OtherClass\' will always evaluate to false.', + 23, + ], + [ + 'Strict comparison using === between class-string and \'Bug3633\\\HelloWorld\' will always evaluate to false.', + 35, + ], + [ + 'Strict comparison using === between class-string and \'Bug3633\\\HelloWorld\' will always evaluate to false.', + 50, + ], + [ + 'Strict comparison using === between class-string and \'Bug3633\\\OtherClass\' will always evaluate to false.', + 53, + ], + [ + 'Strict comparison using === between \'Bug3633\\\FinalClass\' and \'Bug3633\\\FinalClass\' will always evaluate to true.', + 59, + ], + ]); } } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-3633.php b/tests/PHPStan/Rules/Comparison/data/bug-3633.php index 8477f6d403f..f4f2ad637f0 100644 --- a/tests/PHPStan/Rules/Comparison/data/bug-3633.php +++ b/tests/PHPStan/Rules/Comparison/data/bug-3633.php @@ -17,6 +17,13 @@ class HelloWorld { use Foo; public function bar(): void { + if (get_class($this) === HelloWorld::class) { + echo "OK"; + } + if (get_class($this) === OtherClass::class) { + echo "OK"; + } + $this->test(); } } @@ -25,6 +32,34 @@ class OtherClass { use Foo; public function bar(): void { + if (get_class($this) === HelloWorld::class) { + echo "OK"; + } + if (get_class($this) === OtherClass::class) { + echo "OK"; + } + + $this->test(); + } +} + +final class FinalClass { + use Foo; + + public function bar(): void { + if (get_class($this) === HelloWorld::class) { + echo "OK"; + } + if (get_class($this) === OtherClass::class) { + echo "OK"; + } + if (get_class($this) !== FinalClass::class) { + echo "OK"; + } + if (get_class($this) === FinalClass::class) { + echo "OK"; + } + $this->test(); } }