-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathAccessStaticPropertiesRuleTest.php
228 lines (217 loc) · 5.91 KB
/
AccessStaticPropertiesRuleTest.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
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 const PHP_VERSION_ID;
/**
* @extends RuleTestCase<AccessStaticPropertiesRule>
*/
class AccessStaticPropertiesRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
return new AccessStaticPropertiesRule(
$reflectionProvider,
new RuleLevelHelper($reflectionProvider, true, false, true, false, false, true, false),
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
),
);
}
public function testAccessStaticProperties(): void
{
$this->analyse([__DIR__ . '/data/access-static-properties.php'], [
[
'Access to an undefined static property FooAccessStaticProperties::$bar.',
23,
],
[
'Access to an undefined static property BarAccessStaticProperties::$bar.',
24,
],
[
'Access to an undefined static property FooAccessStaticProperties::$bar.',
25,
],
[
'Static access to instance property FooAccessStaticProperties::$loremIpsum.',
26,
],
[
'IpsumAccessStaticProperties::ipsum() accesses parent::$lorem but IpsumAccessStaticProperties does not extend any class.',
42,
],
[
'Access to protected property $foo of class FooAccessStaticProperties.',
44,
],
[
'Access to static property $test on an unknown class UnknownStaticProperties.',
47,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$baz.',
53,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$nonexistent.',
55,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$emptyBaz.',
63,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$emptyNonexistent.',
65,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$anotherNonexistent.',
71,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$anotherNonexistent.',
72,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$anotherEmptyNonexistent.',
75,
],
[
'Access to an undefined static property static(IpsumAccessStaticProperties)::$anotherEmptyNonexistent.',
78,
],
[
'Accessing self::$staticFooProperty outside of class scope.',
84,
],
[
'Accessing static::$staticFooProperty outside of class scope.',
85,
],
[
'Accessing parent::$staticFooProperty outside of class scope.',
86,
],
[
'Access to protected property $foo of class FooAccessStaticProperties.',
89,
],
[
'Static access to instance property FooAccessStaticProperties::$loremIpsum.',
90,
],
[
'Access to an undefined static property FooAccessStaticProperties::$nonexistent.',
94,
],
[
'Access to static property $test on an unknown class NonexistentClass.',
97,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Access to an undefined static property FooAccessStaticProperties&SomeInterface::$nonexistent.',
108,
],
[
'Cannot access static property $foo on int|string.',
113,
],
[
'Class FooAccessStaticProperties referenced with incorrect case: FOOAccessStaticPropertieS.',
119,
],
[
'Access to an undefined static property FooAccessStaticProperties::$unknownProperties.',
119,
],
[
'Class FooAccessStaticProperties referenced with incorrect case: FOOAccessStaticPropertieS.',
120,
],
[
'Static access to instance property FooAccessStaticProperties::$loremIpsum.',
120,
],
[
'Class FooAccessStaticProperties referenced with incorrect case: FOOAccessStaticPropertieS.',
121,
],
[
'Access to protected property $foo of class FooAccessStaticProperties.',
121,
],
[
'Class FooAccessStaticProperties referenced with incorrect case: FOOAccessStaticPropertieS.',
122,
],
[
'Access to an undefined static property ClassOrString|string::$unknownProperty.',
141,
],
[
'Static access to instance property ClassOrString::$instanceProperty.',
152,
],
[
'Access to static property $foo on an unknown class TraitWithStaticProperty.',
209,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Static access to instance property AccessWithStatic::$bar.',
223,
],
[
'Access to an undefined static property static(AccessWithStatic)::$nonexistent.',
224,
],
]);
}
public function testRuleAssignOp(): void
{
if (PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}
$this->analyse([__DIR__ . '/data/access-static-properties-assign-op.php'], [
[
'Access to an undefined static property AccessStaticProperties\AssignOpNonexistentProperty::$flags.',
10,
],
]);
}
public function testClassExists(): void
{
$this->analyse([__DIR__ . '/data/static-properties-class-exists.php'], []);
}
public function testBug5143(): void
{
$this->analyse([__DIR__ . '/data/bug-5143.php'], []);
}
public function testBug6809(): void
{
$errors = [];
$this->analyse([__DIR__ . '/data/bug-6809.php'], $errors);
}
public function testBug8333(): void
{
$this->analyse([__DIR__ . '/data/bug-8333.php'], [
[
'Access to an undefined static property static(Bug8333\BarAccessProperties)::$loremipsum.',
68,
],
[
'Access to private static property $foo of parent class Bug8333\FooAccessProperties.',
69,
],
]);
}
}