- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
test get attributes from params
1 parent
0398c3f
commit 482f506
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Go\ParserReflection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ReflectionAttributesTest extends TestCase | ||
{ | ||
/** | ||
* @var ReflectionFile | ||
*/ | ||
protected $parsedRefFile; | ||
|
||
public function testGetAttributeOnParameters() | ||
{ | ||
$this->setUpFile(__DIR__ . '/Stub/FileWithParameters80.php'); | ||
|
||
$fileNamespace = $this->parsedRefFile->getFileNamespace('Go\ParserReflection\Stub'); | ||
$parameters = $fileNamespace->getFunction('authenticate')->getParameters(); | ||
|
||
foreach ($parameters as $parameter) { | ||
$attributes = $parameter->getAttributes(); | ||
foreach ($attributes as $attribute) { | ||
$originalReflectionParameter = new \ReflectionParameter('Go\ParserReflection\Stub\authenticate', $parameter->getName()); | ||
$originalAttribute = current($originalReflectionParameter->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()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Setups file for parsing | ||
* | ||
* @param string $fileName File name to use | ||
*/ | ||
private function setUpFile($fileName) | ||
{ | ||
$fileName = stream_resolve_include_path($fileName); | ||
$fileNode = ReflectionEngine::parseFile($fileName); | ||
|
||
$reflectionFile = new ReflectionFile($fileName, $fileNode); | ||
$this->parsedRefFile = $reflectionFile; | ||
|
||
include_once $fileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* Parser Reflection API | ||
* | ||
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\ParserReflection\Stub; | ||
|
||
class FileWithClassConstAttribute | ||
{ | ||
public const FOO = 1; | ||
} |