Skip to content

Commit 9dbcae6

Browse files
committed
Add more test for readonly property assignment
1 parent 3fc2d5b commit 9dbcae6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRuleTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,23 @@ public function testBug11495(): void
162162
$this->markTestSkipped('Test requires PHP 8.1.');
163163
}
164164

165-
$errors = [];
166165
if (PHP_VERSION_ID < 80300) {
167-
$errors[] = [
168-
'Readonly property Bug11495\HelloWorld::$foo is assigned outside of the constructor.',
169-
17,
166+
$errors = [
167+
[
168+
'Readonly property Bug11495\HelloWorld::$foo is assigned outside of the constructor.',
169+
17,
170+
],
171+
[
172+
'Readonly property Bug11495\HelloWorld::$foo is assigned outside of the constructor.',
173+
20,
174+
],
175+
];
176+
} else {
177+
$errors = [
178+
[
179+
'Readonly property Bug11495\HelloWorld::$foo is not assigned on $this.',
180+
20,
181+
],
170182
];
171183
}
172184

tests/PHPStan/Rules/Properties/data/bug-11495.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public function __construct()
1515
public function __clone()
1616
{
1717
$this->foo = 'baz';
18+
19+
$s = new self();
20+
$s->foo = 'baz';
1821
}
1922

2023
public function getFoo(): string

0 commit comments

Comments
 (0)