public function testMethod() { $class = new ReflectionClass('Psc\\Code\\Generate\\TestClass2'); $factory = GMethod::reflectorFactory($class->getMethod('factory')); $method2 = GMethod::reflectorFactory($class->getMethod('method2')); $banane = GMethod::reflectorFactory($class->getMethod('banane')); $parameters = $method2->getParameters(); foreach ($parameters as $param) { $this->assertInstanceOf('Psc\\Code\\Generate\\GParameter', $param); } $cr = "\n"; $factoryCode = 'public static function factory(TestHintMethod $dunno) {' . $cr; $factoryCode .= '}'; $this->assertEquals(0, count($factory->getBodyCode())); $this->assertEquals('', $factory->getBody(0)); $method2Code = 'public function method2($num, Array $p1, stdClass $std = NULL, $bun = array()) { // does matter' . $cr; $body = NULL; $body .= '$bimbam = \'pling\';' . $cr; $body .= $cr; $body .= '// anotherinline comment' . $cr; $body .= 'return \'schnurpsel\';' . $cr; $method2Code .= S::indent($body, 2, $cr); $method2Code .= '}'; $method2->getBodyCode(); // 2 mal holen darf die anzahl nicht verdoppeln $this->assertEquals(4, count($method2->getBodyCode())); /* method2 method */ $this->assertEquals($body, $method2->getBody(0), \Webforge\Common\String::debugEquals($body, $method2->getBody(0))); $this->assertEquals($method2Code, $method2->php(), \Webforge\Common\String::debugEquals($method2Code, $method2->php())); /* Factory method */ $this->assertEquals(TRUE, $factory->isStatic()); $this->assertEquals($factoryCode, $factory->php(), \Webforge\Common\String::debugEquals($factoryCode, $factory->php())); $this->assertEquals('abstract public function banane();', $banane->php(), sprintf("output: '%s'", $banane->php())); }
public function elevate(Reflector $reflector) { $this->reflector = $reflector; /* Values erst elevaten damit der namespace + name korrekt ist für equals bei declaring class */ $this->defaultProperties = $this->reflector->getDefaultProperties(); $this->elevateValues('modifiers', 'startLine', 'endLine', array('srcFileName', 'getFileName'), array('name', 'getShortName'), 'interfaces'); $this->setNamespace($this->reflector->getNamespaceName()); /* ClassDocBlock */ $this->elevateDocBlock($this->reflector); foreach ($this->reflector->getMethods() as $rMethod) { try { $gMethod = GMethod::reflectorFactory($rMethod); } catch (ReflectionException $e) { // das ist nicht die von php $e->appendMessage("\n" . 'Methode in: ' . $this->getFQN()); throw $e; } if ($gMethod->getDeclaringClass() instanceof GClassReference && $gMethod->getDeclaringClass()->equals($this)) { $gMethod->setDeclaringClass($this); // replace Reference // source weitergeben $gMethod->setSrcFileName($this->srcFileName); } $this->methods[$gMethod->getName()] = $gMethod; $this->methodsOrder[] = $gMethod->getName(); } foreach ($this->reflector->getProperties() as $rProperty) { $gProperty = GProperty::reflectorFactory($rProperty, $this); if ($gProperty->getDeclaringClass() instanceof GClassReference && $gProperty->getDeclaringClass()->equals($this)) { $gProperty->setDeclaringClass($this); // replace Reference } // nicht addProperty nehmen das würde declaringClass falsch setzen $this->properties[$gProperty->getName()] = $gProperty; } /* Interfaces */ foreach ($this->interfaces as $name => $interface) { $this->interfaces[$name] = new GClass($interface); } /* Constants */ foreach ($this->reflector->getConstants() as $name => $value) { $constant = new GClassConstant($name, $this, $value); $this->constants[$constant->getName()] = $constant; } /* Static Properties */ //@TODO if ($this->reflector->getParentClass() != NULL) { $this->parentClass = new GClass($this->reflector->getParentClass()); } $this->elevated = TRUE; return $this; }