From 2e93957fa89329e172287fecd6d8a74c01f81394 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Fri, 3 Jun 2022 21:55:04 +0200 Subject: [PATCH] Add a promoted property test --- .../Properties/ReadOnlyByPhpDocPropertyRuleTest.php | 5 +++++ .../Properties/data/read-only-property-phpdoc.php | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php index b13c566b4f..94f906d60c 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -18,6 +19,10 @@ protected function getRule(): Rule public function testRule(): void { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + $this->analyse([__DIR__ . '/data/read-only-property-phpdoc.php'], [ [ '@readonly property cannot have a default value.', diff --git a/tests/PHPStan/Rules/Properties/data/read-only-property-phpdoc.php b/tests/PHPStan/Rules/Properties/data/read-only-property-phpdoc.php index 6522f2668b..bb730d8e01 100644 --- a/tests/PHPStan/Rules/Properties/data/read-only-property-phpdoc.php +++ b/tests/PHPStan/Rules/Properties/data/read-only-property-phpdoc.php @@ -1,4 +1,4 @@ -= 8.1 namespace ReadOnlyPropertyPhpDoc; @@ -21,3 +21,13 @@ class Foo private $baz = 0; } + +final class ErrorResponse +{ + public function __construct( + /** @readonly */ + public string $message = '' + ) + { + } +}