From a96d1dfec9f5f24deb79f716bdd7fb6d09d81d9c Mon Sep 17 00:00:00 2001 From: David de Boer Date: Thu, 1 Dec 2022 14:10:49 +0100 Subject: [PATCH 1/6] Allow Psalm 5.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ec787f5..348f2c8 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-simplexml": "*", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/package-versions-deprecated": "^1.10", - "vimeo/psalm": "dev-master || dev-4.x || ^4.5 || ^5@beta" + "vimeo/psalm": "dev-master || dev-4.x || ^4.5 || ^5@beta || ^5.0" }, "conflict": { "phpunit/phpunit": "<7.5" From 0fac00df8c6b00312ef3b794b4c3e94923f1b800 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 1 Dec 2022 11:52:46 -0400 Subject: [PATCH 2/6] Move `config` to the bottom of the file --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 348f2c8..ab47af1 100755 --- a/composer.json +++ b/composer.json @@ -9,10 +9,6 @@ "email": "github@muglug.com" } ], - "config": { - "optimize-autoloader": true, - "sort-packages": true - }, "require": { "php": "^7.1 || ^8.0", "ext-simplexml": "*", @@ -56,5 +52,9 @@ "cs-check": "phpcs", "cs-fix": "phpcbf", "test": "codecept run -v" + }, + "config": { + "optimize-autoloader": true, + "sort-packages": true } } From 3b306f21c8c2e6f5aad1a59d357137179a73b8c4 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 3 Dec 2022 02:09:54 -0400 Subject: [PATCH 3/6] Allow plugin --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab47af1..76aff53 100755 --- a/composer.json +++ b/composer.json @@ -55,6 +55,9 @@ }, "config": { "optimize-autoloader": true, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "composer/package-versions-deprecated": true + } } } From a530027357375e565deadada8c2dbf23640f3d4e Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 3 Dec 2022 02:26:58 -0400 Subject: [PATCH 4/6] Suppress BC issues --- src/Hooks/TestCaseHandler.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index e58a902..caf1315 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -169,10 +169,15 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event foreach ($specials['dataProvider'] as $line => $provider) { try { + // for older Psalm versions + /** + * @psalm-suppress InvalidClone + * @var CodeLocation + */ $provider_docblock_location = clone $method_storage->location; + /** @psalm-suppress UnusedMethodCall */ $provider_docblock_location->setCommentLine($line); } catch (Error $e) { - /** @var CodeLocation */ $provider_docblock_location = $method_storage->location->setCommentLine($line); } @@ -338,11 +343,18 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { + /** @psalm-suppress RedundantCondition */ if (method_exists($param_type, 'setPossiblyUndefined')) { /** @var Union */ $param_type = $param_type->setPossiblyUndefined(true); } else { + // for older Psalm versions + /** + * @psalm-suppress InvalidClone + * @var Union + */ $param_type = clone $param_type; + /** @psalm-suppress InaccessibleProperty */ $param_type->possibly_undefined = true; } } From e2916b71d8beb417e3fabaf5a248cf32d520ded4 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 3 Dec 2022 03:08:47 -0400 Subject: [PATCH 5/6] Update tests for Psalm 5 --- psalm.xml.dist | 2 +- tests/acceptance/Prophecy.feature | 28 +++++++++++++++-- tests/acceptance/TestCase.feature | 50 +++++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/psalm.xml.dist b/psalm.xml.dist index b64f292..04e0d03 100755 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -11,7 +11,7 @@ - + diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature index 2841760..386ecfe 100644 --- a/tests/acceptance/Prophecy.feature +++ b/tests/acceptance/Prophecy.feature @@ -74,7 +74,7 @@ Feature: Prophecy When I run Psalm Then I see no errors - Scenario: Argument::that() only accepts callable with boolean return type + Scenario: Argument::that() only accepts callable with boolean return type [Psalm 4] Given I have the following code """ class MyTestCase extends TestCase @@ -87,12 +87,34 @@ Feature: Prophecy } } """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | - | InvalidScalarArgument | /Argument 1 of Prophecy\\Argument::that expects callable\(mixed...\):bool, (pure-)?Closure\(\):(string\(hello\)\|"hello") provided/ | + | Type | Message | + | InvalidScalarArgument | /Argument 1 of Prophecy\\Argument::that expects callable\(mixed...\):bool, (but )?(pure-)?Closure\(\):(string\(hello\)\|"hello"\|'hello') provided/ | And I see no other errors + Scenario: Argument::that() only accepts callable with boolean return type [Psalm 5] + Given I have the following code + """ + class MyTestCase extends TestCase + { + /** @return void */ + public function testSomething() { + $_argument = Argument::that(function (): string { + return 'hello'; + }); + } + } + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | /Argument 1 of Prophecy\\Argument::that expects callable\(mixed...\):bool, (but )?(pure-)?Closure\(\):(string\(hello\)\|"hello"\|'hello') provided/ | + And I see no other errors + + Scenario: prophesize() provided by ProphecyTrait is generic Given I have the following code """ diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index 1f546a1..744ff6f 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -15,6 +15,13 @@ Feature: TestCase + + + + + + + """ And I have the following code preamble @@ -38,8 +45,8 @@ Feature: TestCase """ When I run Psalm Then I see these errors - | Type | Message | - | InvalidArgument | Argument 1 of NS\MyTestCase::expectException expects class-string, NS\MyTestCase::class provided | + | Type | Message | + | InvalidArgument | /Argument 1 of NS\\MyTestCase::expectException expects class-string, (but )?NS\\MyTestCase::class provided/ | And I see no other errors Scenario: TestCase::expectException() accepts throwables @@ -421,8 +428,8 @@ Feature: TestCase """ When I run Psalm Then I see these errors - | Type | Message | - | InvalidArgument | /Argument 1 of NS\\MyTestCase::testSomething expects int, string provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | + | Type | Message | + | InvalidArgument | /Argument 1 of NS\\MyTestCase::testSomething expects int, string provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | And I see no other errors Scenario: Invalid dataset array is reported @@ -469,8 +476,8 @@ Feature: TestCase """ When I run Psalm Then I see these errors - | Type | Message | - | TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | + | Type | Message | + | TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | And I see no other errors Scenario: Referenced providers are not marked as unused @@ -605,7 +612,7 @@ Feature: TestCase When I run Psalm Then I see no errors - Scenario: Provider omitting offsets is fine when test method has defaults for those params (specified as constants) + Scenario: Provider omitting offsets is fine when test method has defaults for those params (specified as constants) [Psalm 4] Given I have the following code """ class MyTestCase extends TestCase @@ -625,6 +632,31 @@ Feature: TestCase } } """ + And I have Psalm older than "5.0" (because of "sealed shapes") + When I run Psalm + Then I see no errors + + Scenario: Provider omitting offsets is fine when test method has defaults for those params (specified as constants) [Psalm 5] + Given I have the following code + """ + class MyTestCase extends TestCase + { + /** @var string */ + const S = "s"; + /** @return iterable */ + public function provide() { + yield "data set name" => rand(0,1) ? [1] : [1, "ss"]; + } + /** + * @return void + * @dataProvider provide + */ + public function testSomething(int $int, string $_str = self::S) { + $this->assertEquals(1, $int); + } + } + """ + And I have Psalm newer than "4.99" (because of "sealed shapes") When I run Psalm Then I see no errors @@ -960,8 +992,8 @@ Feature: TestCase """ When I run Psalm Then I see these errors - | Type | Message | - | TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | + | Type | Message | + | TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable\)/ | And I see no other errors Scenario: Providers generating incompatible datasets for variadic tests are reported From df68e66525eb8dc7841be22d5927c856d4bb583d Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 3 Dec 2022 03:41:59 -0400 Subject: [PATCH 6/6] Bump Psalm to 4.7.1 Before that Psalm tried to analyze itself and broke tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 76aff53..5f8208b 100755 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "ext-simplexml": "*", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/package-versions-deprecated": "^1.10", - "vimeo/psalm": "dev-master || dev-4.x || ^4.5 || ^5@beta || ^5.0" + "vimeo/psalm": "dev-master || dev-4.x || ^4.7.1 || ^5@beta || ^5.0" }, "conflict": { "phpunit/phpunit": "<7.5"