diff --git a/tests/ReflectionAttributesTest.php b/tests/ReflectionAttributesTest.php index 5cc0a05..9e6e2de 100644 --- a/tests/ReflectionAttributesTest.php +++ b/tests/ReflectionAttributesTest.php @@ -12,6 +12,29 @@ class ReflectionAttributesTest extends TestCase */ protected $parsedRefFile; + public function testGetAttributeOnFunction() + { + $this->setUpFile(__DIR__ . '/Stub/FileWithFunction80.php'); + + $fileNamespace = $this->parsedRefFile->getFileNamespace('Go\ParserReflection\Stub'); + $function = $fileNamespace->getFunction('function_with_attribute'); + $attributes = $function->getAttributes(); + + $originalReflection = new \ReflectionFunction('Go\ParserReflection\Stub\function_with_attribute'); + + foreach ($attributes as $attribute) { + $originalAttribute = current($originalReflection->getAttributes($attribute->getName())); + + $this->assertInstanceOf(ReflectionAttribute::class, $attribute); + $this->assertSame($originalAttribute->getName(), $attribute->getName()); + $this->assertSame($originalAttribute->getName(), $attribute->getName()); + $this->assertSame($originalAttribute->getTarget(), $attribute->getTarget()); + $this->assertSame($originalAttribute->getTarget(), $attribute->getTarget()); + $this->assertSame($originalAttribute->getArguments(), $attribute->getArguments()); + $this->assertSame($originalAttribute->isRepeated(), $attribute->isRepeated()); + } + } + public function testGetAttributeOnParameters() { $this->setUpFile(__DIR__ . '/Stub/FileWithParameters80.php'); diff --git a/tests/Stub/FileWithFunction80.php b/tests/Stub/FileWithFunction80.php new file mode 100644 index 0000000..9d9f1f6 --- /dev/null +++ b/tests/Stub/FileWithFunction80.php @@ -0,0 +1,17 @@ + + * + * This source file is subject to the license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Go\ParserReflection\Stub; + +#[SomeAttribute] +function function_with_attribute() +{ +}