From 0b108f9e97b58cfa0b3da6bc6adf0ad939ee04e8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 15 Mar 2024 10:42:29 +0100 Subject: [PATCH 1/4] Fixup --- composer.json | 4 ++-- src/Hooks/TestCaseHandler.php | 1 + tests/acceptance/Prophecy.feature | 3 +-- tests/acceptance/TestCase.feature | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 5f8208b..3506ee6 100755 --- a/composer.json +++ b/composer.json @@ -10,11 +10,11 @@ } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^7.4 || ^8.0", "ext-simplexml": "*", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/package-versions-deprecated": "^1.10", - "vimeo/psalm": "dev-master || dev-4.x || ^4.7.1 || ^5@beta || ^5.0" + "vimeo/psalm": "dev-master || ^5@beta || ^5.0" }, "conflict": { "phpunit/phpunit": "<7.5" diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index e0c877b..af7e047 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -387,6 +387,7 @@ static function ( } }; + /** @psalm-suppress DeprecatedClass Will be removed soon */ /** @var Type\Atomic\TArray|Type\Atomic\TKeyedArray|Type\Atomic\TList $dataset_type */ $dataset_type = self::getAtomics($provider_return_type->type_params[1])['array']; diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature index 386ecfe..872416a 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 [Psalm 4] + Scenario: Argument::that() only accepts callable with boolean return type Given I have the following code """ class MyTestCase extends TestCase @@ -87,7 +87,6 @@ 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 | diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index 438bdf7..8e0ea86 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -612,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) [Psalm 4] + Scenario: Provider omitting offsets is fine when test method has defaults for those params (specified as constants) Given I have the following code """ class MyTestCase extends TestCase @@ -632,7 +632,6 @@ Feature: TestCase } } """ - And I have Psalm older than "5.0" (because of "sealed shapes") When I run Psalm Then I see no errors From 9732c24ec980ffc46c0cb94aa6f950ccd067843a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 15 Mar 2024 10:56:16 +0100 Subject: [PATCH 2/4] Fixup --- src/Hooks/TestCaseHandler.php | 3 ++- tests/acceptance/Prophecy.feature | 19 ------------------- tests/acceptance/TestCase.feature | 25 +------------------------ 3 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index af7e047..44ca928 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -106,6 +106,8 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) /** * {@inheritDoc} + * + * @psalm-suppress DeprecatedClass TList will be removed soon */ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event) { @@ -387,7 +389,6 @@ static function ( } }; - /** @psalm-suppress DeprecatedClass Will be removed soon */ /** @var Type\Atomic\TArray|Type\Atomic\TKeyedArray|Type\Atomic\TList $dataset_type */ $dataset_type = self::getAtomics($provider_return_type->type_params[1])['array']; diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature index 872416a..eb7d929 100644 --- a/tests/acceptance/Prophecy.feature +++ b/tests/acceptance/Prophecy.feature @@ -74,25 +74,6 @@ Feature: Prophecy When I run Psalm Then I see no errors - Scenario: Argument::that() only accepts callable with boolean return type - Given I have the following code - """ - class MyTestCase extends TestCase - { - /** @return void */ - public function testSomething() { - $_argument = Argument::that(function (): string { - return 'hello'; - }); - } - } - """ - When I run Psalm - Then I see these errors - | 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 """ diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index 8e0ea86..1f818c7 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -612,29 +612,6 @@ 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) - 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); - } - } - """ - 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 """ @@ -1280,7 +1257,7 @@ Feature: TestCase Given I have the following code """ class MyTestCase extends TestCase { - /** @return iterable> */ + /** @return iterable> */ public function provide(): iterable { yield "dataset name" => ["1"]; } From 8b6465dbfedd74ca0d8188a9ceeaa9361e19148f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 15 Mar 2024 11:03:16 +0100 Subject: [PATCH 3/4] Fixup --- src/Hooks/TestCaseHandler.php | 2 +- tests/acceptance/TestCase.feature | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 44ca928..7ac8229 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -106,7 +106,7 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) /** * {@inheritDoc} - * + * * @psalm-suppress DeprecatedClass TList will be removed soon */ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event) diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index 1f818c7..77deed4 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -976,7 +976,7 @@ Feature: TestCase Given I have the following code """ class MyTestCase extends TestCase { - /** @return iterable */ + /** @return iterable */ public function provide() { yield "data set" => [1., "a"]; } @@ -1241,7 +1241,7 @@ Feature: TestCase Given I have the following code """ class MyTestCase extends TestCase { - /** @return iterable> */ + /** @return iterable> */ public function provide(): iterable { yield "dataset name" => [1]; } @@ -1268,7 +1268,7 @@ 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>) | + | InvalidArgument | Argument 1 of NS\MyTestCase::testSomething expects int, string provided by NS\MyTestCase::provide():(iterable>) | Scenario: Providers returning nullable generator are ok Given I have the following code From 455d96a8389703b2eed9020617f53efa139a7b40 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 15 Mar 2024 11:40:24 +0100 Subject: [PATCH 4/4] Hotfix ordering --- tests/acceptance/Prophecy.feature | 2 +- tests/acceptance/TestCase.feature | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature index eb7d929..4f3031a 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 [Psalm 5] + Scenario: Argument::that() only accepts callable with boolean return type Given I have the following code """ class MyTestCase extends TestCase diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index 77deed4..52e7686 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -612,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) [Psalm 5] + Scenario: Provider omitting offsets is fine when test method has defaults for those params (specified as constants) Given I have the following code """ class MyTestCase extends TestCase @@ -1149,21 +1149,6 @@ Feature: TestCase When I run Psalm Then I see no errors - @ExternalProviders - Scenario: Missing external provider classes are reported - Given I have the following code - """ - class MyTestCase extends TestCase { - /** @dataProvider External::provide */ - public function testSomething(int $_p): void {} - } - """ - When I run Psalm - Then I see these errors - | Type | Message | - | UndefinedClass | Class NS\External does not exist | - - @ExternalProviders Scenario: External providers are not marked as unused Given I have the following code @@ -1236,6 +1221,20 @@ Feature: TestCase When I run Psalm on "test.php" Then I see no errors + @ExternalProviders + Scenario: Missing external provider classes are reported + Given I have the following code + """ + class MyTestCase extends TestCase { + /** @dataProvider External::provide */ + public function testSomething(int $_p): void {} + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | UndefinedClass | Class NS\External does not exist | + @List Scenario: Providers returning list are ok Given I have the following code