From 98d16157fc406e51c34dee28d1000b2b13233bed 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 --- .../ReadOnlyByPhpDocPropertyRuleTest.php | 5 +++++ .../Properties/data/read-only-property-phpdoc.php | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php index b13c566b4fd..94f906d60c6 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 6522f2668b8..3ec350f66ff 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,16 @@ class Foo private $baz = 0; } + +final class ErrorResponse +{ + /** + * @param string $message + */ + public function __construct( + /** @readonly */ + public string $message = '' + ) + { + } +}