Skip to content

Commit

Permalink
Fixed missing InternalPropertiesEmulationTrait in ReflectionClassCons…
Browse files Browse the repository at this point in the history
…tant (#100)

Fix missing InternalPropertiesEmulationTrait in ReflectionClassConstant
  • Loading branch information
MaximilianKresse committed Feb 21, 2020
1 parent 6af734c commit e962800
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ReflectionClassConstant.php
Expand Up @@ -11,6 +11,7 @@

namespace Go\ParserReflection;

use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait;
use Go\ParserReflection\ValueResolver\NodeExpressionResolver;
use PhpParser\Node\Const_;
use PhpParser\Node\Stmt\ClassConst;
Expand All @@ -19,6 +20,8 @@

class ReflectionClassConstant extends BaseReflectionClassConstant
{
use InternalPropertiesEmulationTrait;

/**
* Concrete class constant node
*
Expand Down Expand Up @@ -84,13 +87,26 @@ public function __construct(
$this->className = ltrim($className, '\\');

if (!$classConstNode || !$constNode) {
list($classConstNode, $constNode) = ReflectionEngine::parseClassConstant($className, $classConstantName);
[$classConstNode, $constNode] = ReflectionEngine::parseClassConstant($className, $classConstantName);
}
// Let's unset original read-only property to have a control over it via __get
unset($this->name, $this->class);

$this->classConstantNode = $classConstNode;
$this->constNode = $constNode;
}

/**
* Emulating original behaviour of reflection
*/
public function ___debugInfo()
{
return [
'name' => $this->getName(),
'class' => $this->className
];
}

/**
* @inheritDoc
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/ReflectionClassConstantTest.php
Expand Up @@ -53,6 +53,16 @@ public function testGeneralInfoGetters()
}
}

public function testGetClassConstantProperties()
{
$parsedNamespace = $this->parsedRefFile->getFileNamespace('Go\ParserReflection\Stub');
$parsedClass = $parsedNamespace->getClass(ClassWithPhp71Features::class);

$constant = $parsedClass->getReflectionConstant('PUBLIC_CONST_A');
$this->assertSame('PUBLIC_CONST_A', $constant->name);
$this->assertSame(ClassWithPhp71Features::class, $constant->class);
}

public function testGetClassConstant()
{
$parsedNamespace = $this->parsedRefFile->getFileNamespace('Go\ParserReflection\Stub');
Expand Down

0 comments on commit e962800

Please sign in to comment.