Repository navigation
Expand file tree
/
Copy pathCallUserFuncRuleTest.php
More file actions
198 lines (188 loc) · 5.17 KB
/
Copy pathCallUserFuncRuleTest.php
File metadata and controls
198 lines (188 loc) · 5.17 KB
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
190
191
192
193
194
195
196
197
198
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Functions;
use PHPStan\Rules\FunctionCallParametersCheck;
use PHPStan\Rules\NullsafeCheck;
use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
/**
* @extends RuleTestCase<CallUserFuncRule>
*/
class CallUserFuncRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$reflectionProvider = self::createReflectionProvider();
return new CallUserFuncRule(
$reflectionProvider,
new FunctionCallParametersCheck(
new RuleLevelHelper(
$reflectionProvider,
checkNullables: true,
checkThisOnly: false,
checkUnionTypes: true,
checkExplicitMixed: true,
checkImplicitMixed: false,
checkBenevolentUnionTypes: false,
discoveringSymbolsTip: true,
),
new NullsafeCheck(),
new UnresolvableTypeHelper(),
new PropertyReflectionFinder(),
$reflectionProvider,
checkArgumentTypes: true,
checkArgumentsPassedByReference: true,
checkExtraArguments: true,
checkMissingTypehints: true,
reportMixedTernaryAndCoalesce: true,
),
);
}
#[RequiresPhp('>= 8.0.0')]
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/call-user-func.php'], [
[
'Callable passed to call_user_func() invoked with 0 parameters, 1 required.',
15,
],
[
'Parameter #1 $i of callable passed to call_user_func() expects int, string given.',
17,
],
[
'Parameter $i of callable passed to call_user_func() expects int, string given.',
18,
],
[
'Parameter $i of callable passed to call_user_func() expects int, string given.',
19,
],
[
'Unknown parameter $j in call to callable passed to call_user_func().',
22,
],
[
'Missing parameter $i (int) in call to callable passed to call_user_func().',
22,
],
[
'Callable passed to call_user_func() invoked with 0 parameters, 2-4 required.',
30,
],
[
'Callable passed to call_user_func() invoked with 1 parameter, 2-4 required.',
31,
],
[
'Callable passed to call_user_func() invoked with 0 parameters, at least 2 required.',
40,
],
[
'Callable passed to call_user_func() invoked with 1 parameter, at least 2 required.',
41,
],
[
'Result of callable passed to call_user_func() (void) is used.',
43,
],
]);
}
#[RequiresPhp('>= 8.0.0')]
public function testRuleCallUserFuncArray(): void
{
$this->analyse([__DIR__ . '/data/call-user-func-array.php'], [
[
'Callable passed to call_user_func_array() invoked with 0 parameters, 1 required.',
15,
],
[
'Parameter #1 $i of callable passed to call_user_func_array() expects int, string given.',
17,
],
[
'Parameter $i of callable passed to call_user_func_array() expects int, string given.',
18,
],
[
'Parameter $i of callable passed to call_user_func_array() expects int, string given.',
19,
],
[
'Unknown parameter $j in call to callable passed to call_user_func_array().',
22,
],
[
'Missing parameter $i (int) in call to callable passed to call_user_func_array().',
22,
],
[
'Callable passed to call_user_func_array() invoked with 0 parameters, 2-4 required.',
30,
],
[
'Callable passed to call_user_func_array() invoked with 1 parameter, 2-4 required.',
31,
],
[
'Callable passed to call_user_func_array() invoked with 0 parameters, at least 2 required.',
40,
],
[
'Callable passed to call_user_func_array() invoked with 1 parameter, at least 2 required.',
41,
],
[
'Result of callable passed to call_user_func_array() (void) is used.',
43,
],
[
'Parameter #1 $i of callable passed to call_user_func_array() expects int|null, string given.',
52,
],
[
'Parameter #1 $i of callable passed to call_user_func_array() expects int|null, string given.',
53,
],
]);
}
public function testBug7057(): void
{
$this->analyse([__DIR__ . '/data/bug-7057.php'], []);
}
#[RequiresPhp('>= 8.1.0')]
public function testNoNamedArguments(): void
{
$this->analyse([__DIR__ . '/data/no-named-arguments-call-user-func.php'], [
[
'Callable passed to call_user_func() invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.',
29,
],
[
'Callable passed to call_user_func() invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.',
30,
],
[
'Callable passed to call_user_func() invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.',
31,
],
[
'Callable passed to call_user_func() invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.',
32,
],
]);
}
#[RequiresPhp('>= 8.0')]
public function testConstantParameterCheckCallUserFunc(): void
{
$this->analyse([__DIR__ . '/data/constant-parameter-check-call-user-func.php'], [
[
'Constant SORT_REGULAR is not allowed for parameter #2 $flags of callable passed to call_user_func().',
9,
],
]);
}
}