Skip to content

Commit cd2ebfa

Browse files
committed
test: test cases for Argument::that
1 parent 1000bb6 commit cd2ebfa

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

tests/acceptance/Prophecy.feature

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Feature: Prophecy
2+
In order to utilize Prophecy in my test cases
3+
As a Psalm user
4+
I need Psalm to typecheck my prophecies
5+
6+
Background:
7+
Given I have the following config
8+
"""
9+
<?xml version="1.0"?>
10+
<psalm totallyTyped="true" %s>
11+
<projectFiles>
12+
<directory name="."/>
13+
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
14+
</projectFiles>
15+
<plugins>
16+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
17+
</plugins>
18+
</psalm>
19+
"""
20+
And I have the following code preamble
21+
"""
22+
<?php
23+
namespace NS;
24+
use PHPUnit\Framework\TestCase;
25+
use Prophecy\Argument;
26+
27+
"""
28+
29+
Scenario: Argument::that() accepts callable with no parameters
30+
Given I have the following code
31+
"""
32+
class MyTestCase extends TestCase
33+
{
34+
/** @return void */
35+
public function testSomething() {
36+
$argument = Argument::that(function () {
37+
return true;
38+
});
39+
}
40+
}
41+
"""
42+
When I run Psalm
43+
Then I see no errors
44+
45+
Scenario: Argument::that() accepts callable with one parameter
46+
Given I have the following code
47+
"""
48+
class MyTestCase extends TestCase
49+
{
50+
/** @return void */
51+
public function testSomething() {
52+
$argument = Argument::that(function (int $i) {
53+
return $i > 0;
54+
});
55+
}
56+
}
57+
"""
58+
When I run Psalm
59+
Then I see no errors
60+
61+
Scenario: Argument::that() accepts callable with multiple parameters
62+
Given I have the following code
63+
"""
64+
class MyTestCase extends TestCase
65+
{
66+
/** @return void */
67+
public function testSomething() {
68+
$argument = Argument::that(function (int $i, int $j, int $k) {
69+
return ($i + $j + $k) > 0;
70+
});
71+
}
72+
}
73+
"""
74+
When I run Psalm
75+
Then I see no errors
76+
77+
Scenario: Argument::that() only accepts callable with boolean return type
78+
Given I have the following code
79+
"""
80+
class MyTestCase extends TestCase
81+
{
82+
/** @return void */
83+
public function testSomething() {
84+
$argument = Argument::that(function (): string {
85+
return 'hello';
86+
});
87+
}
88+
}
89+
"""
90+
When I run Psalm
91+
Then I see these errors
92+
| InvalidScalarArgument | Argument 1 of Prophecy\Argument::that expects callable(mixed...):bool, Closure():string(hello) provided |

0 commit comments

Comments
 (0)