From ffc0495d89763b65d93256928cb95bc4b07f6138 Mon Sep 17 00:00:00 2001 From: Takuya Aramaki Date: Mon, 15 May 2023 03:44:33 +0900 Subject: [PATCH] Regression test Closes https://github.com/phpstan/phpstan/issues/8412 --- .../MissingReadOnlyPropertyAssignRuleTest.php | 9 +++++++ .../Rules/Properties/data/bug-8412.php | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-8412.php diff --git a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php index fc67094134..23456c8934 100644 --- a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php @@ -129,4 +129,13 @@ public function testBug7314(): void $this->analyse([__DIR__ . '/data/bug-7314.php'], []); } + public function testBug8412(): void + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + + $this->analyse([__DIR__ . '/data/bug-8412.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-8412.php b/tests/PHPStan/Rules/Properties/data/bug-8412.php new file mode 100644 index 0000000000..2fdc39dbbf --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-8412.php @@ -0,0 +1,25 @@ += 8.1 + +namespace Bug8412; + +use InvalidArgumentException; + +enum Zustand: string +{ + case Failed = 'failed'; + case Pending = 'pending'; +} + +final class HelloWorld +{ + public readonly ?int $value; + + public function __construct(Zustand $zustand) + { + $this->value = match ($zustand) { + Zustand::Failed => 1, + Zustand::Pending => 2, + default => throw new InvalidArgumentException('Unknown Zustand: ' . $zustand->value), + }; + } +}