-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathMethodCallableRuleTest.php
More file actions
88 lines (78 loc) · 2.04 KB
/
MethodCallableRuleTest.php
File metadata and controls
88 lines (78 loc) · 2.04 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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Methods;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<MethodCallableRule>
*/
class MethodCallableRuleTest extends RuleTestCase
{
private int $phpVersion = PHP_VERSION_ID;
protected function getRule(): Rule
{
$reflectionProvider = self::createReflectionProvider();
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, false, true, false, false, false, true);
return new MethodCallableRule(
new MethodCallCheck($reflectionProvider, $ruleLevelHelper, true, true),
new PhpVersion($this->phpVersion),
);
}
#[RequiresPhp('< 8.1')]
public function testNotSupportedOnOlderVersions(): void
{
$this->analyse([__DIR__ . '/data/method-callable-not-supported.php'], [
[
'First-class callables are supported only on PHP 8.1 and later.',
10,
],
]);
}
#[RequiresPhp('>= 8.1')]
public function testBug13596(): void
{
$this->analyse([__DIR__ . '/data/bug-13596.php'], []);
}
#[RequiresPhp('>= 8.1')]
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/method-callable.php'], [
[
'Call to method MethodCallable\Foo::doFoo() with incorrect case: dofoo',
11,
],
[
'Call to an undefined method MethodCallable\Foo::doNonexistent().',
12,
],
[
'Cannot call method doFoo() on int.',
13,
],
[
'Call to private method doBar() of class MethodCallable\Bar.',
18,
],
[
'Call to method doFoo() on an unknown class MethodCallable\Nonexistent.',
23,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Call to private method doFoo() of class MethodCallable\ParentClass.',
53,
],
[
'Creating callable from a non-native method MethodCallable\Lorem::doBar().',
66,
],
[
'Creating callable from a non-native method MethodCallable\Ipsum::doBar().',
85,
],
]);
}
}