Repository navigation
Expand file tree
/
Copy pathStaticMethodCallableRuleTest.php
More file actions
109 lines (98 loc) · 2.73 KB
/
Copy pathStaticMethodCallableRuleTest.php
File metadata and controls
109 lines (98 loc) · 2.73 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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Methods;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\ClassCaseSensitivityCheck;
use PHPStan\Rules\ClassForbiddenNameCheck;
use PHPStan\Rules\ClassNameCheck;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<StaticMethodCallableRule>
*/
class StaticMethodCallableRuleTest 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);
$container = self::getContainer();
return new StaticMethodCallableRule(
new StaticMethodCallCheck(
$reflectionProvider,
$ruleLevelHelper,
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck($container),
$reflectionProvider,
$container,
),
true,
true,
true,
),
new PhpVersion($this->phpVersion),
);
}
#[RequiresPhp('< 8.1')]
public function testNotSupportedOnOlderVersions(): void
{
$this->analyse([__DIR__ . '/data/static-method-callable-not-supported.php'], [
[
'First-class callables are supported only on PHP 8.1 and later.',
10,
],
]);
}
#[RequiresPhp('>= 8.1')]
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/static-method-callable.php'], [
[
'Call to static method StaticMethodCallable\Foo::doFoo() with incorrect case: dofoo',
11,
],
[
'Call to static method doFoo() on an unknown class StaticMethodCallable\Nonexistent.',
12,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Call to an undefined static method StaticMethodCallable\Foo::nonexistent().',
13,
],
[
'Static call to instance method StaticMethodCallable\Foo::doBar().',
14,
],
[
'Call to private static method doBar() of class StaticMethodCallable\Bar.',
15,
],
[
'Cannot call abstract static method StaticMethodCallable\Bar::doBaz().',
16,
],
[
'Call to static method doFoo() on an unknown class StaticMethodCallable\Nonexistent.',
21,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Cannot call static method doFoo() on int.',
22,
],
]);
}
public function testBug8752(): void
{
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8752.php'], []);
}
public function testCallsOnGenericClassString(): void
{
$this->analyse([__DIR__ . '/../Comparison/data/impossible-method-exists-on-generic-class-string.php'], []);
}
}