From 6e361aa9e67fecbbc70e2147e1cf016efcbf00a7 Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Wed, 7 Feb 2024 08:59:49 +0000 Subject: [PATCH] Failed and regression tests for magic static methods List failed tests: ``` 1) Psalm\Tests\MagicMethodAnnotationTest::testNoSealAllMethodsWithStatic Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown. 2) Psalm\Tests\MagicMethodAnnotationTest::testSealAllMethodsWithoutFooWithStatic Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown. 3) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCode with data set "inheritSealedMethodsWithStatic" Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown. ``` --- tests/MagicMethodAnnotationTest.php | 238 ++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index 6b7f05e32..6a92fa4de 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -46,6 +46,35 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testPhpDocMethodWhenUndefinedWithStatic(): void + { + Config::getInstance()->use_phpdoc_method_without_magic_or_parent = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', new Context()); + } + public function testPhpDocMethodWhenTemplated(): void { Config::getInstance()->use_phpdoc_method_without_magic_or_parent = true; @@ -99,6 +128,28 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', $context); } + public function testAnnotationWithoutCallConfigWithStatic(): void + { + $this->expectExceptionMessage('UndefinedMethod'); + $this->expectException(CodeException::class); + Config::getInstance()->use_phpdoc_method_without_magic_or_parent = false; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } + public function testOverrideParentClassRetunType(): void { Config::getInstance()->use_phpdoc_method_without_magic_or_parent = true; @@ -193,6 +244,48 @@ class MagicMethodAnnotationTest extends TestCase '$e' => 'callable():string', ], ], + 'validSimpleAnnotationsWithStatic' => [ + 'code' => ' [ + '$a' => 'string', + '$b' => 'mixed', + '$c' => 'bool', + '$d' => 'array', + '$e' => 'callable():string', + '$f' => 'Child', + ], + ], 'validAnnotationWithDefault' => [ 'code' => 'foo();', 'error_message' => 'UndefinedMagicMethod', ], + 'inheritSealedMethodsWithStatic' => [ + 'code' => ' 'UndefinedMagicMethod', + ], 'lonelyMethod' => [ 'code' => 'analyzeFile('somefile.php', new Context()); } + public function testSealAllMethodsWithoutFooWithStatic(): void + { + Config::getInstance()->seal_all_methods = true; + + $this->addFile( + 'somefile.php', + 'expectException(CodeException::class); + $this->expectExceptionMessage($error_message); + $this->analyzeFile('somefile.php', new Context()); + } + public function testNoSealAllMethods(): void { Config::getInstance()->seal_all_methods = true; @@ -1199,6 +1329,30 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testNoSealAllMethodsWithStatic(): void + { + Config::getInstance()->seal_all_methods = true; + + $this->addFile( + 'somefile.php', + 'expectException(CodeException::class); + $this->expectExceptionMessage($error_message); + $this->analyzeFile('somefile.php', new Context()); + } + public function testSealAllMethodsWithFoo(): void { Config::getInstance()->seal_all_methods = true; @@ -1221,6 +1375,27 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testSealAllMethodsWithFooWithStatic(): void + { + Config::getInstance()->seal_all_methods = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', new Context()); + } + public function testSealAllMethodsWithFooInSubclass(): void { Config::getInstance()->seal_all_methods = true; @@ -1244,6 +1419,28 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testSealAllMethodsWithFooInSubclassWithStatic(): void + { + Config::getInstance()->seal_all_methods = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', new Context()); + } + public function testSealAllMethodsWithFooAnnotated(): void { Config::getInstance()->seal_all_methods = true; @@ -1266,6 +1463,27 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testSealAllMethodsWithFooAnnotatedWithStatic(): void + { + Config::getInstance()->seal_all_methods = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', new Context()); + } + public function testSealAllMethodsSetToFalse(): void { Config::getInstance()->seal_all_methods = false; @@ -1287,6 +1505,26 @@ class MagicMethodAnnotationTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testSealAllMethodsSetToFalseWithStatic(): void + { + Config::getInstance()->seal_all_methods = false; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', new Context()); + } + public function testIntersectionTypeWhenMagicMethodDoesNotExistButIsProvidedBySecondType(): void { $this->addFile(