-
Notifications
You must be signed in to change notification settings - Fork 426
/
CallToNonExistentFunctionRuleTest.php
189 lines (166 loc) · 4.38 KB
/
CallToNonExistentFunctionRuleTest.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Functions;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<CallToNonExistentFunctionRule>
*/
class CallToNonExistentFunctionRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new CallToNonExistentFunctionRule($this->createReflectionProvider(), true);
}
public function testEmptyFile(): void
{
$this->analyse([__DIR__ . '/data/empty.php'], []);
}
public function testCallToExistingFunction(): void
{
require_once __DIR__ . '/data/existing-function-definition.php';
$this->analyse([__DIR__ . '/data/existing-function.php'], []);
}
public function testCallToNonexistentFunction(): void
{
$this->analyse([__DIR__ . '/data/nonexistent-function.php'], [
[
'Function foobarNonExistentFunction not found.',
5,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testCallToNonexistentNestedFunction(): void
{
$this->analyse([__DIR__ . '/data/nonexistent-nested-function.php'], [
[
'Function barNonExistentFunction not found.',
5,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testCallToIncorrectCaseFunctionName(): void
{
require_once __DIR__ . '/data/incorrect-function-case-definition.php';
$this->analyse([__DIR__ . '/data/incorrect-function-case.php'], [
[
'Call to function IncorrectFunctionCase\fooBar() with incorrect case: foobar',
5,
],
[
'Call to function IncorrectFunctionCase\fooBar() with incorrect case: IncorrectFunctionCase\foobar',
7,
],
[
'Call to function htmlspecialchars() with incorrect case: htmlSpecialChars',
10,
],
]);
}
public function testMatchExprAnalysis(): void
{
$this->analyse([__DIR__ . '/data/match-expr-analysis.php'], [
[
'Function lorem not found.',
10,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function ipsum not found.',
11,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function dolor not found.',
11,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function sit not found.',
12,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testCreateFunctionPhp8(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$this->analyse([__DIR__ . '/data/create_function.php'], [
[
'Function create_function not found.',
4,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testCreateFunctionPhp7(): void
{
if (PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('Test requires PHP 7.x.');
}
$this->analyse([__DIR__ . '/data/create_function.php'], []);
}
public function testBug3576(): void
{
$this->analyse([__DIR__ . '/data/bug-3576.php'], [
[
'Function bug3576 not found.',
14,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function bug3576 not found.',
17,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function bug3576 not found.',
26,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function bug3576 not found.',
29,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function bug3576 not found.',
38,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Function bug3576 not found.',
41,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testBug7952(): void
{
$this->analyse([__DIR__ . '/data/bug-7952.php'], []);
}
public function testBug8058(): void
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('Test requires PHP 8.2');
}
$this->analyse([__DIR__ . '/../Methods/data/bug-8058.php'], []);
}
public function testBug8058b(): void
{
if (PHP_VERSION_ID >= 80200) {
$this->markTestSkipped('Test requires PHP before 8.2');
}
$this->analyse([__DIR__ . '/../Methods/data/bug-8058.php'], [
[
'Function mysqli_execute_query not found.',
13,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
}