forked from psalm/psalm-plugin-phpunit
/
Prophecy.feature
110 lines (103 loc) · 3.11 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
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
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, (pure-)?Closure\(\):(string\(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