/
ReadOnlyByPhpDocPropertyAssignRuleTest.php
150 lines (138 loc) · 4.01 KB
/
ReadOnlyByPhpDocPropertyAssignRuleTest.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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
use PHPStan\Reflection\ConstructorsHelper;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<ReadOnlyByPhpDocPropertyAssignRule>
*/
class ReadOnlyByPhpDocPropertyAssignRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new ReadOnlyByPhpDocPropertyAssignRule(
new PropertyReflectionFinder(),
new ConstructorsHelper(
[
'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.',
40,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$bar is assigned outside of its declaring class.',
53,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
54,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$psalm is assigned outside of its declaring class.',
55,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$bar is assigned outside of its declaring class.',
60,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$psalm is assigned outside of its declaring class.',
61,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
68,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\FooArrays::$details is assigned outside of the constructor.',
87,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\FooArrays::$details is assigned outside of the constructor.',
88,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\NotThis::$foo is not assigned on $this.',
118,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
134,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
135,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\PostInc::$foo is assigned outside of the constructor.',
137,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\ListAssign::$foo is assigned outside of the constructor.',
158,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\ListAssign::$foo is assigned outside of the constructor.',
163,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
173,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Foo::$baz is assigned outside of its declaring class.',
174,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\Immutable::$foo is assigned outside of the constructor.',
237,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\B::$b is assigned outside of the constructor.',
269,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\A::$a is assigned outside of its declaring class.',
270,
],
[
'@readonly property ReadonlyPropertyAssignPhpDoc\C::$c is assigned outside of the constructor.',
283,
],
]);
}
public function testRuleIgnoresNativeReadonly(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$this->analyse([__DIR__ . '/data/readonly-assign-phpdoc-and-native.php'], []);
}
public function testBug7361(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$this->analyse([__DIR__ . '/data/bug-7361.php'], [
[
'@readonly property Bug7361\Example::$foo is assigned outside of the constructor.',
12,
],
]);
}
public function testFeature7648(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$this->analyse([__DIR__ . '/data/feature-7648.php'], []);
}
}