-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
HookCallbackRuleTest.php
67 lines (60 loc) · 2.11 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
<?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 has no return value.',
17,
],
[
'Filter callback has no return value.',
20,
],
[
'Filter callback has no return value.',
21,
],
[
'Callback expects 1 argument, $accepted_args is set to 0.',
24,
],
[
'Callback expects 1 argument, $accepted_args is set to 2.',
27,
],
[
'Callback expects 2 arguments, $accepted_args is set to 1.',
30,
],
]
);
}
public static function getAdditionalConfigFiles(): array
{
return [dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon'];
}
}