Skip to content

Commit

Permalink
test for property
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Feb 2, 2024
1 parent 773ca7b commit b967bef
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tests/ReflectionAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public function testGetAttributeOnParameters()

foreach ($parameters as $parameter) {
$attributes = $parameter->getAttributes();
$originalReflectionParameter = new \ReflectionParameter('Go\ParserReflection\Stub\authenticate', $parameter->getName());
$originalReflection = new \ReflectionParameter('Go\ParserReflection\Stub\authenticate', $parameter->getName());

foreach ($attributes as $attribute) {
$originalAttribute = current($originalReflectionParameter->getAttributes($attribute->getName()));
$originalAttribute = current($originalReflection->getAttributes($attribute->getName()));

$this->assertInstanceOf(ReflectionAttribute::class, $attribute);
$this->assertSame($originalAttribute->getName(), $attribute->getName());
Expand All @@ -47,11 +47,36 @@ public function testGetAttributeOnClassConst()
foreach (array_keys($constants) as $constant) {
$reflectionClassConst = new ReflectionClassConstant('Go\ParserReflection\Stub\FileWithClassConstAttribute', $constant);
$attributes = $reflectionClassConst->getAttributes();
$originalReflectionClassConst = new \ReflectionClassConstant('Go\ParserReflection\Stub\FileWithClassConstAttribute', $constant);
$originalReflection = new \ReflectionClassConstant('Go\ParserReflection\Stub\FileWithClassConstAttribute', $constant);

foreach ($attributes as $attribute) {

$originalAttribute = current($originalReflectionClassConst->getAttributes($attribute->getName()));
$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 testGetAttributeOnProperty()
{
$this->setUpFile(__DIR__ . '/Stub/FileWithClassProperty80.php');

$fileNamespace = $this->parsedRefFile->getFileNamespace('Go\ParserReflection\Stub');
$properties = $fileNamespace->getClass('Go\ParserReflection\Stub\FileWithClassProperty')->getProperties();

foreach ($properties as $property) {
$attributes = $property->getAttributes();
$originalReflection = new \ReflectionProperty('Go\ParserReflection\Stub\FileWithClassProperty', $property->getName());

foreach ($attributes as $attribute) {
$originalAttribute = current($originalReflection->getAttributes($attribute->getName()));

$this->assertInstanceOf(ReflectionAttribute::class, $attribute);
$this->assertSame($originalAttribute->getName(), $attribute->getName());
Expand Down
18 changes: 18 additions & 0 deletions tests/Stub/FileWithClassProperty80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* Parser Reflection API
*
* @copyright Copyright 2015, Lisachenko Alexander <lisachenko.it@gmail.com>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/

namespace Go\ParserReflection\Stub;

class FileWithClassProperty
{
#[\Doctrine\ORM\Mapping\Id]
public $id;
}

0 comments on commit b967bef

Please sign in to comment.