-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathReadOnlyByPhpDocPropertyAssignRuleTest.php
More file actions
199 lines (187 loc) · 5.45 KB
/
ReadOnlyByPhpDocPropertyAssignRuleTest.php
File metadata and controls
199 lines (187 loc) · 5.45 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
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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
use PHPStan\Reflection\ConstructorsHelper;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
/**
* @extends RuleTestCase<ReadOnlyByPhpDocPropertyAssignRule>
*/
class ReadOnlyByPhpDocPropertyAssignRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new ReadOnlyByPhpDocPropertyAssignRule(
new PropertyReflectionFinder(),
new ConstructorsHelper(
self::getContainer(),
[
'ReadonlyPropertyAssignPhpDoc\\TestCase::setUp',
],
),
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/readonly-assign-phpdoc.php'], [
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$foo is assigned outside of the constructor.',
47,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$phan is assigned outside of the constructor.',
49,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$bar is assigned outside of its declaring class.',
61,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
62,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$psalm is assigned outside of its declaring class.',
63,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$phan is assigned outside of its declaring class.',
64,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$bar is assigned outside of its declaring class.',
69,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$psalm is assigned outside of its declaring class.',
70,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$phan is assigned outside of its declaring class.',
71,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
78,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\FooArrays::$details is assigned outside of the constructor.',
97,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\FooArrays::$details is assigned outside of the constructor.',
98,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\NotThis::$foo is not assigned on $this.',
128,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
144,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
145,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
147,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\ListAssign::$foo is assigned outside of the constructor.',
168,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\ListAssign::$foo is assigned outside of the constructor.',
173,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
183,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
184,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Immutable::$foo is assigned outside of the constructor.',
247,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\B::$b is assigned outside of the constructor.',
279,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\A::$a is assigned outside of its declaring class.',
280,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\C::$c is assigned outside of the constructor.',
293,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\ArrayAccessPropertyFetch::$storage is assigned outside of the constructor.',
311,
],
]);
}
#[RequiresPhp('>= 8.1')]
public function testRuleIgnoresNativeReadonly(): void
{
$this->analyse([__DIR__ . '/data/readonly-assign-phpdoc-and-native.php'], []);
}
#[RequiresPhp('>= 8.1')]
public function testBug7361(): void
{
$this->analyse([__DIR__ . '/data/bug-7361.php'], [
[
'@readonly property Bug7361\Example::$foo is assigned outside of the constructor.',
12,
],
]);
}
#[RequiresPhp('>= 8.1')]
public function testFeature7648(): void
{
$this->analyse([__DIR__ . '/data/feature-7648.php'], []);
}
#[RequiresPhp('>= 7.4')]
public function testFeature11775(): void
{
$this->analyse([__DIR__ . '/data/feature-11775.php'], [
[
'@readonly property Feature11775\FooImmutable::$i is assigned outside of the constructor.',
22,
],
[
'@readonly property Feature11775\FooReadonly::$i is assigned outside of the constructor.',
43,
],
]);
}
#[RequiresPhp('>= 8.4')]
public function testPropertyHooks(): void
{
$this->analyse([__DIR__ . '/data/property-hooks-readonly-by-phpdoc-assign.php'], [
[
'@readonly property PropertyHooksReadonlyByPhpDocAssign\Foo::$i is assigned outside of the constructor.',
15,
],
[
'@readonly property PropertyHooksReadonlyByPhpDocAssign\Foo::$j is assigned outside of the constructor.',
17,
],
]);
}
#[RequiresPhp('>= 8.5')]
public function testCloneWith(): void
{
$this->analyse([__DIR__ . '/data/readonly-phpdoc-property-assign-clone-with.php'], [
[
'@readonly property ReadonlyPhpDocPropertyAssignCloneWith\Foo::$pub is assigned outside of its declaring class.',
29,
],
]);
}
}