Skip to content

Commit

Permalink
Update tests for Psalm 5
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Dec 3, 2022
1 parent a530027 commit e2916b7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion psalm.xml.dist
Expand Up @@ -11,7 +11,7 @@

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
<UnnecessaryVarAnnotation errorLevel="suppress" />
<UnnecessaryVarAnnotation errorLevel="suppress" />
</issueHandlers>

<plugins>
Expand Down
28 changes: 25 additions & 3 deletions tests/acceptance/Prophecy.feature
Expand Up @@ -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
Expand All @@ -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
"""
Expand Down
50 changes: 41 additions & 9 deletions tests/acceptance/TestCase.feature
Expand Up @@ -15,6 +15,13 @@ Feature: TestCase
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
<issueHandlers>
<DeprecatedMethod>
<errorLevel type="suppress">
<referencedMethod name="PhpUnit\Framework\TestCase::prophesize"/>
</errorLevel>
</DeprecatedMethod>
</issueHandlers>
</psalm>
"""
And I have the following code preamble
Expand All @@ -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<Throwable>, NS\MyTestCase::class provided |
| Type | Message |
| InvalidArgument | /Argument 1 of NS\\MyTestCase::expectException expects class-string<Throwable>, (but )?NS\\MyTestCase::class provided/ |
And I see no other errors

Scenario: TestCase::expectException() accepts throwables
Expand Down Expand Up @@ -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<string, array\{(0: )?string\}>\)/ |
| Type | Message |
| InvalidArgument | /Argument 1 of NS\\MyTestCase::testSomething expects int, string provided by NS\\MyTestCase::provide\(\):\(iterable<string, (array\{(0: )?string\}\|list\{string\})>\)/ |
And I see no other errors

Scenario: Invalid dataset array is reported
Expand Down Expand Up @@ -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<string, array\{(0: )?int\}>\)/ |
| Type | Message |
| TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable<string, (array\{(0: )?int\}\|list\{int\})>\)/ |
And I see no other errors

Scenario: Referenced providers are not marked as unused
Expand Down Expand Up @@ -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
Expand All @@ -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<string,list{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 newer than "4.99" (because of "sealed shapes")
When I run Psalm
Then I see no errors

Expand Down Expand Up @@ -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<string, array\{(0: )?int\}>\)/ |
| Type | Message |
| TooFewArguments | /Too few arguments for NS\\MyTestCase::testSomething - expecting at least 2, but saw 1 provided by NS\\MyTestCase::provide\(\):\(iterable<string, (array\{(0: )?int\}\|list\{int\})>\)/ |
And I see no other errors

Scenario: Providers generating incompatible datasets for variadic tests are reported
Expand Down

0 comments on commit e2916b7

Please sign in to comment.