Skip to content

Commit 06e46c2

Browse files
committed
test subclass
1 parent 944d4f0 commit 06e46c2

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

tests/PHPStan/Rules/Variables/UnsetRuleTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,27 @@ public function testBug12421(): void
9696
$this->analyse([__DIR__ . '/data/bug-12421.php'], [
9797
[
9898
'Cannot unset property y of readonly class Bug12421\NativeReadonlyClass.',
99-
78,
99+
11,
100100
],
101101
[
102102
'Cannot unset readonly property y of Bug12421\NativeReadonlyProperty.',
103-
82,
103+
15,
104104
],
105105
[
106106
'Cannot unset property y of immutable class Bug12421\PhpdocReadonlyClass.',
107-
86,
107+
19,
108108
],
109109
[
110110
'Cannot unset @readonly property y of Bug12421\PhpdocReadonlyProperty.',
111-
90,
111+
23,
112112
],
113113
[
114114
'Cannot unset property y of immutable class Bug12421\PhpdocImmutableClass.',
115-
94,
115+
27,
116+
],
117+
[
118+
'Cannot unset readonly property y of Bug12421\NativeReadonlyPropertySubClass.',
119+
34,
116120
],
117121
]);
118122
}

tests/PHPStan/Rules/Variables/data/bug-12421.php

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
namespace Bug12421;
44

5+
function doFoo() {
6+
$x = new RegularProperty();
7+
unset($x->y);
8+
var_dump($x->y);
9+
10+
$x = new NativeReadonlyClass();
11+
unset($x->y);
12+
var_dump($x->y);
13+
14+
$x = new NativeReadonlyProperty();
15+
unset($x->y);
16+
var_dump($x->y);
17+
18+
$x = new PhpdocReadonlyClass();
19+
unset($x->y);
20+
var_dump($x->y);
21+
22+
$x = new PhpdocReadonlyProperty();
23+
unset($x->y);
24+
var_dump($x->y);
25+
26+
$x = new PhpdocImmutableClass();
27+
unset($x->y);
28+
var_dump($x->y);
29+
30+
$x = new \stdClass();
31+
unset($x->y);
32+
33+
$x = new NativeReadonlyPropertySubClass();
34+
unset($x->y);
35+
var_dump($x->y);
36+
}
37+
538
readonly class NativeReadonlyClass
639
{
740
public Y $y;
@@ -65,37 +98,11 @@ public function __construct()
6598
}
6699
}
67100

68-
class Y
101+
class NativeReadonlyPropertySubClass extends NativeReadonlyProperty
69102
{
70103
}
71104

72-
function doFoo() {
73-
$x = new RegularProperty();
74-
unset($x->y);
75-
var_dump($x->y);
76-
77-
$x = new NativeReadonlyClass();
78-
unset($x->y);
79-
var_dump($x->y);
80-
81-
$x = new NativeReadonlyProperty();
82-
unset($x->y);
83-
var_dump($x->y);
84-
85-
$x = new PhpdocReadonlyClass();
86-
unset($x->y);
87-
var_dump($x->y);
88-
89-
$x = new PhpdocReadonlyProperty();
90-
unset($x->y);
91-
var_dump($x->y);
92-
93-
$x = new PhpdocImmutableClass();
94-
unset($x->y);
95-
var_dump($x->y);
96-
97-
$x = new \stdClass();
98-
unset($x->y);
99-
105+
class Y
106+
{
100107
}
101108

0 commit comments

Comments
 (0)