Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to MixedReturnStatement, drop Psalm 4 support #142

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/Hooks/TestCaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
22 changes: 1 addition & 21 deletions tests/acceptance/Prophecy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +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]
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 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, (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]
Scenario: Argument::that() only accepts callable with boolean return type
Given I have the following code
"""
class MyTestCase extends TestCase
Expand Down
63 changes: 19 additions & 44 deletions tests/acceptance/TestCase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -612,31 +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]
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @var string */
const S = "s";
/** @return iterable<string,array{0:int}> */
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 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]
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
Expand Down Expand Up @@ -1000,7 +976,7 @@ Feature: TestCase
Given I have the following code
"""
class MyTestCase extends TestCase {
/** @return iterable<string,array{float,1?:string}> */
/** @return iterable<string,array{0: float, 1?:string}> */
public function provide() {
yield "data set" => [1., "a"];
}
Expand Down Expand Up @@ -1173,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
Expand Down Expand Up @@ -1260,12 +1221,26 @@ 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
"""
class MyTestCase extends TestCase {
/** @return iterable<string, list<int>> */
/** @return iterable<string, non-empty-list<int>> */
public function provide(): iterable {
yield "dataset name" => [1];
}
Expand All @@ -1281,7 +1256,7 @@ Feature: TestCase
Given I have the following code
"""
class MyTestCase extends TestCase {
/** @return iterable<string, list<string>> */
/** @return iterable<string, non-empty-list<string>> */
public function provide(): iterable {
yield "dataset name" => ["1"];
}
Expand All @@ -1292,7 +1267,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<string, list<string>>) |
| InvalidArgument | Argument 1 of NS\MyTestCase::testSomething expects int, string provided by NS\MyTestCase::provide():(iterable<string, non-empty-list<string>>) |

Scenario: Providers returning nullable generator are ok
Given I have the following code
Expand Down