public function testGetClass()
 {
     $refClass = $this->parsedRefFileNamespace->getClass('Unknown');
     $this->assertFalse($refClass);
     $refClass = $this->parsedRefFileNamespace->getClass(TestNamespaceClassFoo::class);
     $this->assertInstanceOf(\ReflectionClass::class, $refClass);
     $this->assertEquals(TestNamespaceClassFoo::class, $refClass->name);
 }
 public function testGetConstant()
 {
     $parsedRefClass = $this->parsedRefFileNamespace->getClass(ClassWithScalarConstants::class);
     $originalRefClass = new \ReflectionClass(ClassWithScalarConstants::class);
     $this->assertSame($originalRefClass->getConstant('D'), $parsedRefClass->getConstant('D'));
     $this->assertSame($originalRefClass->getConstant('E'), $parsedRefClass->getConstant('E'));
 }
 /**
  * Utility method to fetch reflection class instance by name
  *
  * Supports:
  *   'self' keyword
  *   'parent' keyword
  *    not-FQN class names
  *
  * @param Node\Name $node Class name node
  *
  * @return bool|\ReflectionClass
  *
  * @throws ReflectionException
  */
 private function fetchReflectionClass(Node\Name $node)
 {
     $className = $node->toString();
     $isFQNClass = $node instanceof Node\Name\FullyQualified;
     if ($isFQNClass) {
         return new ReflectionClass($className);
     }
     if ('self' === $className) {
         if ($this->context instanceof \ReflectionClass) {
             return $this->context;
         } elseif (method_exists($this->context, 'getDeclaringClass')) {
             return $this->context->getDeclaringClass();
         }
     }
     if ('parent' === $className) {
         if ($this->context instanceof \ReflectionClass) {
             return $this->context->getParentClass();
         } elseif (method_exists($this->context, 'getDeclaringClass')) {
             return $this->context->getDeclaringClass()->getParentClass();
         }
     }
     if (method_exists($this->context, 'getFileName')) {
         /** @var ReflectionFileNamespace|null $fileNamespace */
         $fileName = $this->context->getFileName();
         $namespaceName = $this->context->getNamespaceName();
         $fileNamespace = new ReflectionFileNamespace($fileName, $namespaceName);
         return $fileNamespace->getClass($className);
     }
     throw new ReflectionException("Can not resolve class {$className}");
 }