diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index 507f64e2..ba3c52f5 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -80,6 +80,9 @@ public function build(\Reflector $reflector, Context $context): array $instance->nullable = $nullable ?: Generator::UNDEFINED; if ($rp->isPromoted()) { + // ensure each property has its own context + $instance->_context = new Context([], $instance->_context); + // promoted parameter - docblock is available via class/property if ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment()) { $instance->_context->comment = $comment; diff --git a/tests/Analysers/ReflectionAnalyserTest.php b/tests/Analysers/ReflectionAnalyserTest.php index b8fd6d3d..3a07bf63 100644 --- a/tests/Analysers/ReflectionAnalyserTest.php +++ b/tests/Analysers/ReflectionAnalyserTest.php @@ -195,8 +195,17 @@ public function testPhp8PromotedProperties(): void /** @var OA\Property[] $properties */ $properties = $analysis->getAnnotationsOfType(OA\Property::class); - $this->assertCount(2, $properties); - $this->assertEquals('id', $properties[0]->property); - $this->assertEquals('labels', $properties[1]->property); + + [$tags, $id, $labels] = $properties; + + $this->assertCount(3, $properties); + $this->assertEquals('tags', $tags->property); + $this->assertEquals('id', $id->property); + $this->assertEquals('labels', $labels->property); + + // regression: check doc blocks + $this->assertStringContainsString('Label List', $labels->_context->comment); + $this->assertStringContainsString('Tag List', $tags->_context->comment); + $this->assertEmpty($id->_context->comment); } } diff --git a/tests/Analysers/TokenScannerTest.php b/tests/Analysers/TokenScannerTest.php index b58feec4..db198d96 100644 --- a/tests/Analysers/TokenScannerTest.php +++ b/tests/Analysers/TokenScannerTest.php @@ -232,7 +232,7 @@ public static function scanCases(): iterable 'traits' => [], 'enums' => [], 'methods' => ['__construct'], - 'properties' => ['labels', 'id'], + 'properties' => ['labels', 'tags', 'id'], ], ], ]; diff --git a/tests/Fixtures/PHP/Php8PromotedProperties.php b/tests/Fixtures/PHP/Php8PromotedProperties.php index 1cfeeb22..c28ad37f 100644 --- a/tests/Fixtures/PHP/Php8PromotedProperties.php +++ b/tests/Fixtures/PHP/Php8PromotedProperties.php @@ -23,6 +23,13 @@ public function __construct( * @OA\Property() */ public ?array $labels, + /** + * Tag List. + * + * @var array + */ + #[OAT\Property()] + public array $tags, #[OAT\Property()] public int $id, ) {