From 02a9ac7cd50f1a6142c7861b7a695b78dc426f42 Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Fri, 11 Feb 2022 12:50:26 -0600 Subject: [PATCH 01/17] Improve provider non-optional argument phrasing I just ran across a case where I added an argument to a test method and forgot to give it a default value, and this made all previous arguments with defaults non-optional. The phrasing here confused me because I could clearly see that the argument it was complaining about had a default value, and it took me a while to find the actual issue that I forgot to add a default value to the new argument. --- src/Hooks/TestCaseHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 5645a4e..dd1e6b6 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -345,7 +345,7 @@ static function ( } elseif ($potential_argument_type->possibly_undefined && !$is_optional) { IssueBuffer::accepts(new Issue\InvalidArgument( 'Argument ' . ($param_offset + 1) . ' of ' . $method_name - . ' has no default value, but possibly undefined ' + . ' is not optional, but possibly undefined ' . $potential_argument_type->getId() . ' provided' . ' by ' . $provider_method_id . '():(' . $provider_return_type_string . ')', $provider_docblock_location From e1a4e2e287fceb3cb847d670af52f86d65d52892 Mon Sep 17 00:00:00 2001 From: Mougrim Date: Sun, 22 May 2022 17:01:43 +0300 Subject: [PATCH 02/17] Fix tests for new version psalm Signed-off-by: Mougrim --- psalm.xml.dist | 2 +- tests/acceptance/Prophecy.feature | 2 +- tests/acceptance/TestCase.feature | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psalm.xml.dist b/psalm.xml.dist index 2224d90..b64f292 100755 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -1,6 +1,6 @@ - + diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index dd36870..1f546a1 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -7,7 +7,7 @@ Feature: TestCase Given I have the following config """ - + @@ -693,8 +693,8 @@ Feature: TestCase """ When I run Psalm Then I see these errors - | Type | Message | - | InvalidArgument | Argument 1 of NS\MyTestCase::testSomething has no default value, but possibly undefined int provided by NS\MyTestCase::provide():(iterable) | + | Type | Message | + | InvalidArgument | Argument 1 of NS\MyTestCase::testSomething is not optional, but possibly undefined int provided by NS\MyTestCase::provide():(iterable) | And I see no other errors Scenario: Stateful grandchild test case with setUp produces no MissingConstructor From 86a1ecf51463f1281a1d3876363b2969ba771334 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 12 Jun 2022 19:10:12 +0200 Subject: [PATCH 03/17] Add getMockForAbstractClass stub --- stubs/MockBuilder.phpstub | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/MockBuilder.phpstub b/stubs/MockBuilder.phpstub index fc1578b..bf3dfb1 100644 --- a/stubs/MockBuilder.phpstub +++ b/stubs/MockBuilder.phpstub @@ -24,6 +24,11 @@ class MockBuilder */ public function getMock() {} + /** + * @return MockObject&T + */ + public function getMockForAbstractClass() {} + /** * Specifies the subset of methods to mock. Default is to mock none of them. * From 486c4dd837d03f886d0ec15275eb96578483e679 Mon Sep 17 00:00:00 2001 From: someniatko Date: Fri, 29 Jul 2022 15:25:01 +0300 Subject: [PATCH 04/17] [composer.json] allow Psalm 5 beta --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5ff36fa..ec787f5 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" + "vimeo/psalm": "dev-master || dev-4.x || ^4.5 || ^5@beta" }, "conflict": { "phpunit/phpunit": "<7.5" From 803eb8585f9540b3c50118817179cced6b58a4b3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 22 Oct 2022 22:17:19 +0200 Subject: [PATCH 05/17] Immutable refactoring --- src/Hooks/TestCaseHandler.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index dd1e6b6..1f0f83c 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -164,8 +164,7 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - $provider_docblock_location = clone $method_storage->location; - $provider_docblock_location->setCommentLine($line); + $provider_docblock_location = $method_storage->location->setCommentLine($line); if (false !== strpos($provider, '::')) { [$class_name, $method_id] = explode('::', $provider); @@ -328,9 +327,8 @@ static function ( $provider_return_type_string, $provider_docblock_location ): void { - $param_type = clone $param_type; if ($is_optional) { - $param_type->possibly_undefined = true; + $param_type = $param_type->setPossiblyUndefined(true); } if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { // ok From e5889774b0520a0a87365fd75b94707a32a97ae8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 31 Oct 2022 21:42:45 +0100 Subject: [PATCH 06/17] BC fixes --- src/Hooks/TestCaseHandler.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 1f0f83c..f6b4e5a 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -8,10 +8,12 @@ use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use Psalm\Codebase; +use Psalm\CodeLocation; use Psalm\DocComment; use Psalm\Exception\DocblockParseException; use Psalm\IssueBuffer; use Psalm\Issue; +use Psalm\PhpUnitPlugin\VersionUtils; use Psalm\Plugin\EventHandler\AfterClassLikeAnalysisInterface; use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface; use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface; @@ -21,6 +23,7 @@ use Psalm\Storage\ClassLikeStorage; use Psalm\Type; use Psalm\Type\Atomic\TNull; +use Psalm\Type\Union; use RuntimeException; class TestCaseHandler implements @@ -164,7 +167,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - $provider_docblock_location = $method_storage->location->setCommentLine($line); + if (VersionUtils::packageVersionIs('vimeo/psalm', '>=', '5.0')) { + /** @var CodeLocation */ + $provider_docblock_location = $method_storage->location->setCommentLine($line); + } else { + $provider_docblock_location = clone $method_storage->location; + $provider_docblock_location->setCommentLine($line); + } if (false !== strpos($provider, '::')) { [$class_name, $method_id] = explode('::', $provider); @@ -328,7 +337,13 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { - $param_type = $param_type->setPossiblyUndefined(true); + if (method_exists($param_type, 'setPossiblyUndefined')) { + /** @var Union */ + $param_type = $param_type->setPossiblyUndefined(true); + } else { + $param_type = clone $param_type; + $param_type->possibly_undefined = true; + } } if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { // ok From 1421076bc80ed60258a8a3291dad2a94c9758f12 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 31 Oct 2022 21:44:32 +0100 Subject: [PATCH 07/17] Improve --- src/Hooks/TestCaseHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index f6b4e5a..0ecf897 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -167,12 +167,12 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - if (VersionUtils::packageVersionIs('vimeo/psalm', '>=', '5.0')) { - /** @var CodeLocation */ - $provider_docblock_location = $method_storage->location->setCommentLine($line); - } else { + if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) { $provider_docblock_location = clone $method_storage->location; $provider_docblock_location->setCommentLine($line); + } else { + /** @var CodeLocation */ + $provider_docblock_location = $method_storage->location->setCommentLine($line); } if (false !== strpos($provider, '::')) { From 9044b30475630b2498b97f742943610ccef3ee1a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 1 Nov 2022 13:40:16 +0100 Subject: [PATCH 08/17] Fix --- src/Hooks/TestCaseHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 0ecf897..57a64b7 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -337,12 +337,12 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { - if (method_exists($param_type, 'setPossiblyUndefined')) { - /** @var Union */ - $param_type = $param_type->setPossiblyUndefined(true); - } else { + if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) { $param_type = clone $param_type; $param_type->possibly_undefined = true; + } else { + /** @var Union */ + $param_type = $param_type->setPossiblyUndefined(true); } } if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { From 4c17270abaa8408426d5f56cb7392707779de0ce Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 2 Nov 2022 00:07:48 +0100 Subject: [PATCH 09/17] Allow running in PR --- src/Hooks/TestCaseHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 57a64b7..950b12d 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -167,7 +167,7 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) { + if (VersionUtils::packageVersionIs('vimeo/psalm', '<=', '4.99')) { $provider_docblock_location = clone $method_storage->location; $provider_docblock_location->setCommentLine($line); } else { @@ -337,7 +337,7 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { - if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) { + if (VersionUtils::packageVersionIs('vimeo/psalm', '<=', '4.99')) { $param_type = clone $param_type; $param_type->possibly_undefined = true; } else { From 1b62fa7d8d62dae23cacf60ec2f17dfbf983034e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 3 Nov 2022 12:44:36 +0100 Subject: [PATCH 10/17] Dumb version detection --- src/Hooks/TestCaseHandler.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 950b12d..c9bcc4a 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -4,6 +4,7 @@ namespace Psalm\PhpUnitPlugin\Hooks; +use Error; use PhpParser\Comment\Doc; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; @@ -167,10 +168,10 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - if (VersionUtils::packageVersionIs('vimeo/psalm', '<=', '4.99')) { + try { $provider_docblock_location = clone $method_storage->location; $provider_docblock_location->setCommentLine($line); - } else { + } catch (Error $_) { /** @var CodeLocation */ $provider_docblock_location = $method_storage->location->setCommentLine($line); } @@ -337,12 +338,12 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { - if (VersionUtils::packageVersionIs('vimeo/psalm', '<=', '4.99')) { - $param_type = clone $param_type; - $param_type->possibly_undefined = true; - } else { + if (method_exists($param_type, 'setPossiblyUndefined')) { /** @var Union */ $param_type = $param_type->setPossiblyUndefined(true); + } else { + $param_type = clone $param_type; + $param_type->possibly_undefined = true; } } if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { From eb6969540a88a599e62b9ba8738b09b4f0ef69bb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 3 Nov 2022 19:03:03 +0100 Subject: [PATCH 11/17] Fix typo, it turns out $_ is used later on as a ref parameter --- src/Hooks/TestCaseHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index c9bcc4a..e58a902 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -171,7 +171,7 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event try { $provider_docblock_location = clone $method_storage->location; $provider_docblock_location->setCommentLine($line); - } catch (Error $_) { + } catch (Error $e) { /** @var CodeLocation */ $provider_docblock_location = $method_storage->location->setCommentLine($line); } From a96d1dfec9f5f24deb79f716bdd7fb6d09d81d9c Mon Sep 17 00:00:00 2001 From: David de Boer Date: Thu, 1 Dec 2022 14:10:49 +0100 Subject: [PATCH 12/17] 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 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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"