diff --git a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php index 71e1c09473..72bd938449 100644 --- a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php @@ -54,6 +54,14 @@ public function testRule(): void 'Access to an uninitialized readonly property MissingReadOnlyPropertyAssign\AssignOp::$bar.', 87, ], + [ + 'Readonly property MissingReadOnlyPropertyAssign\DoubleAssign::$foo is already assigned.', + 128, + ], + [ + 'Class MissingReadOnlyPropertyAssign\Foo has an maybe uninitialized readonly property $foo.', + 139, + ], ]); } diff --git a/tests/PHPStan/Rules/Properties/data/missing-readonly-property-assign.php b/tests/PHPStan/Rules/Properties/data/missing-readonly-property-assign.php index e6671cf9c5..91fac724dc 100644 --- a/tests/PHPStan/Rules/Properties/data/missing-readonly-property-assign.php +++ b/tests/PHPStan/Rules/Properties/data/missing-readonly-property-assign.php @@ -101,3 +101,42 @@ public function __construct(int $foo) } } + +class ValidDoubleAssign +{ + private readonly int $foo; + + public function __construct(int $foo) + { + if (rand(0, 1)) { + $this->foo = $foo; + } else { + $this->foo = 0; + } + } +} + +class DoubleAssign +{ + private readonly int $foo; + + public function __construct(int $foo) + { + if (rand(0, 1)) { + $this->foo = $foo; + } + $this->foo = 0; + } +} + +class MaybeUninitialized +{ + private readonly int $foo; + + public function __construct(int $foo) + { + if (rand(0, 1)) { + $this->foo = $foo; + } + } +}