public function testGetSetValueForObjectMethods()
 {
     $parsedProperty = $this->parsedRefClass->getProperty('protectedProperty');
     $parsedProperty->setAccessible(true);
     $className = self::STUB_CLASS;
     $obj = new $className();
     $value = $parsedProperty->getValue($obj);
     $this->assertSame('a', $value);
     $parsedProperty->setValue($obj, 43);
     $value = $parsedProperty->getValue($obj);
     $this->assertSame(43, $value);
 }
Пример #2
0
 /**
  * Locates a file name for class
  *
  * @param string $fullClassName Full name of the class
  *
  * @return string
  */
 public static function locateClassFile($fullClassName)
 {
     if (class_exists($fullClassName, false) || interface_exists($fullClassName, false) || trait_exists($fullClassName, false)) {
         $refClass = new \ReflectionClass($fullClassName);
         $classFileName = $refClass->getFileName();
     } else {
         $classFileName = self::$locator->locateClass($fullClassName);
     }
     if (!$classFileName) {
         throw new \InvalidArgumentException("Class {$fullClassName} was not found by locator");
     }
     return $classFileName;
 }
 private function recursiveCollect(\Closure $collector)
 {
     $result = [];
     $isParent = true;
     $traits = $this->getTraits();
     foreach ($traits as $trait) {
         $collector($result, $trait, !$isParent);
     }
     $parentClass = $this->getParentClass();
     if ($parentClass) {
         $collector($result, $parentClass, $isParent);
     }
     $interfaces = ReflectionClass::collectInterfacesFromClassNode($this->classLikeNode);
     foreach ($interfaces as $interface) {
         $collector($result, $interface, $isParent);
     }
     return $result;
 }
 /**
  * Implementation of internal reflection initialization
  *
  * @return void
  */
 protected function __initialize()
 {
     parent::__construct($this->getName());
 }
 public function testLocateClass()
 {
     $locator = new ComposerLocator();
     $reflectionClass = new \ReflectionClass(ReflectionClass::class);
     $this->assertSame($reflectionClass->getFileName(), $locator->locateClass(ReflectionClass::class));
 }
 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'));
 }