/
HookCallbackRuleTest.php
127 lines (120 loc) · 4.26 KB
/
HookCallbackRuleTest.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
<?php
declare(strict_types=1);
namespace SzepeViktor\PHPStan\WordPress\Tests;
use PHPStan\Rules\RuleLevelHelper;
use SzepeViktor\PHPStan\WordPress\HookCallbackRule;
/**
* @extends \PHPStan\Testing\RuleTestCase<\SzepeViktor\PHPStan\WordPress\HookCallbackRule>
*/
class HookCallbackRuleTest extends \PHPStan\Testing\RuleTestCase
{
protected function getRule(): \PHPStan\Rules\Rule
{
/** @var \PHPStan\Rules\RuleLevelHelper */
$ruleLevelHelper = self::getContainer()->getByType(RuleLevelHelper::class);
// getRule() method needs to return an instance of the tested rule
return new HookCallbackRule($ruleLevelHelper);
}
// phpcs:ignore NeutronStandard.Functions.LongFunction.LongFunction
public function testRule(): void
{
// first argument: path to the example file that contains some errors that should be reported by HookCallbackRule
// second argument: an array of expected errors,
// each error consists of the asserted error message, and the asserted error file line
$this->analyse(
[
__DIR__ . '/data/hook-callback.php',
],
[
[
'Filter callback return statement is missing.',
17,
],
[
'Filter callback return statement is missing.',
20,
],
[
'Filter callback return statement is missing.',
23,
],
[
'Callback expects 1 parameter, $accepted_args is set to 0.',
26,
],
[
'Callback expects 1 parameter, $accepted_args is set to 2.',
31,
],
[
'Callback expects 0-1 parameters, $accepted_args is set to 2.',
36,
],
[
'Callback expects 2 parameters, $accepted_args is set to 1.',
41,
],
[
'Callback expects 2-4 parameters, $accepted_args is set to 1.',
46,
],
[
'Callback expects 2-3 parameters, $accepted_args is set to 4.',
51,
],
[
'Action callback returns true but should not return anything.',
56,
],
[
'Action callback returns true but should not return anything.',
61,
],
[
'Filter callback return statement is missing.',
68,
],
[
'Action callback returns false but should not return anything.',
71,
],
[
'Action callback returns int but should not return anything.',
74,
],
[
'Callback expects at least 1 parameter, $accepted_args is set to 0.',
77,
],
[
'Callback expects at least 1 parameter, $accepted_args is set to 0.',
80,
],
[
'Callback expects 0-3 parameters, $accepted_args is set to 4.',
85,
],
[
'Action callback returns int but should not return anything.',
90,
],
[
'Callback expects 0 parameters, $accepted_args is set to 2.',
93,
],
[
'Action callback returns false but should not return anything.',
96,
],
[
'Action callback returns mixed but should not return anything.',
99,
],
]
);
}
public static function getAdditionalConfigFiles(): array
{
return [dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon'];
}
}