diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php index 6304fa93b..6a891075f 100644 --- a/src/Reflection/ReflectionClass.php +++ b/src/Reflection/ReflectionClass.php @@ -768,6 +768,7 @@ public function getImmediateProperties(?int $filter = null): array [new Node\Stmt\PropertyProperty($parameterNameNode->name, $parameterNode->default)], $parameterNode->getAttributes(), $parameterNode->type, + $parameterNode->attrGroups, ); $property = ReflectionProperty::createFromNode( $this->reflector, diff --git a/test/unit/Fixture/Attributes.php b/test/unit/Fixture/Attributes.php index 6fccf8a6a..e736de63e 100644 --- a/test/unit/Fixture/Attributes.php +++ b/test/unit/Fixture/Attributes.php @@ -39,6 +39,14 @@ public function methodWithAttributes( { } + + public function __construct( + #[Attr] + #[AnotherAttr] + private $promotedPropertyWithAttributes + ) + { + } } #[Attr] diff --git a/test/unit/Reflection/ReflectionPropertyTest.php b/test/unit/Reflection/ReflectionPropertyTest.php index 3fe22c3a5..3ce5afadf 100644 --- a/test/unit/Reflection/ReflectionPropertyTest.php +++ b/test/unit/Reflection/ReflectionPropertyTest.php @@ -872,31 +872,48 @@ public function testGetAttributesWithoutAttributes(): void self::assertCount(0, $attributes); } - public function testGetAttributesWithAttributes(): void + public function dataGetAttributes(): array + { + return [ + ['propertyWithAttributes'], + ['promotedPropertyWithAttributes'], + ]; + } + + /** + * @dataProvider dataGetAttributes + */ + public function testGetAttributesWithAttributes(string $propertyName): void { $reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/Attributes.php', $this->astLocator)); $classReflection = $reflector->reflectClass(ClassWithAttributes::class); - $propertyReflection = $classReflection->getProperty('propertyWithAttributes'); + $propertyReflection = $classReflection->getProperty($propertyName); $attributes = $propertyReflection->getAttributes(); self::assertCount(2, $attributes); } - public function testGetAttributesByName(): void + /** + * @dataProvider dataGetAttributes + */ + public function testGetAttributesByName(string $propertyName): void { $reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/Attributes.php', $this->astLocator)); $classReflection = $reflector->reflectClass(ClassWithAttributes::class); - $propertyReflection = $classReflection->getProperty('propertyWithAttributes'); + $propertyReflection = $classReflection->getProperty($propertyName); $attributes = $propertyReflection->getAttributesByName(Attr::class); self::assertCount(1, $attributes); } - public function testGetAttributesByInstance(): void + /** + * @dataProvider dataGetAttributes + */ + public function testGetAttributesByInstance(string $propertyName): void { $reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/Attributes.php', $this->astLocator)); $classReflection = $reflector->reflectClass(ClassWithAttributes::class); - $propertyReflection = $classReflection->getProperty('propertyWithAttributes'); + $propertyReflection = $classReflection->getProperty($propertyName); $attributes = $propertyReflection->getAttributesByInstance(Attr::class); self::assertCount(2, $attributes);