-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathCallUserFuncRuleTest.php
More file actions
105 lines (97 loc) · 2.94 KB
/
CallUserFuncRuleTest.php
File metadata and controls
105 lines (97 loc) · 2.94 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
<?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, true, false, true, true, false, false, true), new NullsafeCheck(), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), $reflectionProvider, true, true, true, true));
}
#[RequiresPhp('>= 8.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,
],
]);
}
public function testBug7057(): void
{
$this->analyse([__DIR__ . '/data/bug-7057.php'], []);
}
#[RequiresPhp('>= 8.1')]
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,
],
]);
}
}