-
Notifications
You must be signed in to change notification settings - Fork 34
/
Prophecy.feature
132 lines (123 loc) · 4.09 KB
/
Prophecy.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Feature: Prophecy
In order to utilize Prophecy in my test cases
As a Psalm user
I need Psalm to typecheck my prophecies
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm errorLevel="1" %s>
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
"""
And I have the following code preamble
"""
<?php
namespace NS;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
"""
Scenario: Argument::that() accepts callable with no parameters
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
$_argument = Argument::that(function () {
return true;
});
}
}
"""
When I run Psalm
Then I see no errors
Scenario: Argument::that() accepts callable with one parameter
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
$_argument = Argument::that(function (int $i) {
return $i > 0;
});
}
}
"""
When I run Psalm
Then I see no errors
Scenario: Argument::that() accepts callable with multiple parameters
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
$_argument = Argument::that(function (int $i, int $j, int $k) {
return ($i + $j + $k) > 0;
});
}
}
"""
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]
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
"""
use Prophecy\PhpUnit\ProphecyTrait;
class SUT { public function getString(): string { return "zzz"; } }
class MyTestCase extends TestCase
{
use ProphecyTrait;
public function testSomething(): void {
$this->prophesize(SUT::class)->reveal()->getString();
}
}
"""
When I run Psalm
Then I see no errors