Esempio n. 1
0
 public function createStub(GClass $class)
 {
     $setupCode = "\$this->chainClass = '%s';\n";
     $setupCode .= "parent::setUp();\n";
     if ($this->class->isAbstract()) {
         $setupCode .= '//$this->%s = $this->getMockForAbstractClass($this->chainClass);' . "\n";
     } else {
         $setupCode .= "//\$this->%s = new %s();\n";
     }
     $docBlock = $class->createDocBlock();
     $docBlock->addSimpleAnnotation('group class:' . $this->class->getFQN());
     $class->addMethod(new GMethod('setUp', array(), sprintf($setupCode, $this->class->getFQN(), lcfirst($this->class->getClassName()), $this->class->getClassName())));
     $class->addMethod(new GMethod('testAcceptance', array(), '$this->markTestIncomplete(\'Stub vom Test-Creater\');'));
     //$class->addMethod(new GMethod('create'.$this->class->getClassName(), array(),
     //sprintf("return new %s();",$this->class->getClassName())), GMethod::MODIFIER_PROTECTED);
     $class->createProperty(lcfirst($this->class->getClassName()), GProperty::MODIFIER_PROTECTED);
     return $class;
 }
Esempio n. 2
0
 public function createClassMetadata(GClass $gClass)
 {
     // da wir gClass mehrmals im Test evalen könnten, erzeugen wir einen unique hash für den classname und übergeben den
     // der class metadata
     $className = uniqid($gClass->getClassName());
     $gClass->setClassName($className);
     $gClass->createDocBlock()->addAnnotation(Annotation::createDC('Entity'));
     $classWriter = new ClassWriter($gClass);
     $classWriter->setUseStyle('lines');
     $classWriter->addImport(new GClass('Doctrine\\ORM\\Mapping'), 'ORM');
     // braucht einen AnnotationReader nicht SimpleAnnotationReader
     $classWriter->write($file = $this->newFile('entity.' . $gClass->getClassName() . '.php'));
     require $file;
     $cm = new ClassMetadata($gClass->getFQN());
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->annotationDriver->loadMetadataForClass($gClass->getFQN(), $cm);
     $file->delete();
     return $cm;
 }
Esempio n. 3
0
 public function __call($method, $args)
 {
     $prop = mb_strtolower(mb_substr($method, 3, 1)) . mb_substr($method, 4);
     // ucfirst in mb_string
     /* getter der nicht implementiert ist */
     if (mb_strpos($method, 'get') === 0) {
         if ($this->annotationClass->hasProperty($prop)) {
             return $this->annotation->{$prop};
         } else {
             throw new MissingPropertyException($prop, 'Annotation: ' . $this->annotationClass->getFQN() . " hat kein Feld '" . $prop . "'");
         }
     }
     /* setter der nicht implementiert ist */
     if (mb_strpos($method, 'set') === 0) {
         if ($this->annotationClass->hasProperty($prop)) {
             $this->annotation->{$prop} = $args[0];
             return $this;
         } else {
             throw new MissingPropertyException($prop, 'Annotation: ' . $this->annotationClass->getFQN() . " hat kein Feld '" . $prop . "'");
         }
     }
     throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
 }
Esempio n. 4
0
 /**
  * @TODO test interfaces und extends!
  */
 public function testClass()
 {
     $cr = "\n";
     $class = GClass::factory(__NAMESPACE__ . '\\TestClass');
     $this->assertInstanceOf('Psc\\Code\\Generate\\GMethod', $class->getMethod('method2'));
     $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $class->getProperty('prop1'));
     $gClass = new GClass('Psc\\Code\\Generate\\GClass');
     $this->assertEquals('GClass', $gClass->getClassName());
     $this->assertEquals('\\Psc\\Code\\Generate', $gClass->getNamespace());
     $this->assertEquals('Psc\\Code\\Generate\\GClass', $gClass->getFQN());
     /* test final + abstract zeuch */
     $this->assertFalse($gClass->isFinal());
     $this->assertFalse($gClass->isAbstract());
     $gClass->setFinal(TRUE);
     $this->assertTrue($gClass->isFinal());
     $gClass->setAbstract(TRUE);
     $this->assertTrue($gClass->isAbstract());
     $gClass->setModifier(GClass::MODIFIER_ABSTRACT, FALSE);
     $gClass->setModifier(GClass::MODIFIER_FINAL, FALSE);
     $this->assertFalse($gClass->isAbstract());
     $this->assertFalse($gClass->isFinal());
     /* testClass (denn da wissen wir die line-nummern besser und die ist auch abstract */
     $testClass = new GClass(new ReflectionClass(__NAMESPACE__ . '\\TestClass'));
     $this->assertTrue($testClass->isAbstract());
     $this->assertFalse($testClass->isFinal());
     $this->assertEquals(self::$startLine, $testClass->getStartLine());
     $this->assertEquals(self::$endLine, $testClass->getEndLine());
     $testHint = new GClass('SomeClassForAHint');
     $this->assertEquals('class SomeClassForAHint {' . $cr . '}', $testHint->php(), sprintf("output: '%s'", $testHint->php()));
     //file_put_contents('D:\fixture.txt', self::$testClassCode);
     //file_put_contents('D:\compiled.txt',$testClass->php());
     $this->assertEquals(self::$testClassCode, $testClass->php(), 'Code für Klasse ist nicht identisch');
     //identisch bis auf whitespaces! (das ist irgendwie ein bissl variabel, aber okay
     // geiler wäre halt assertEqualsCode, hmmm das ginge sogar mit token_get_all und so?
 }
Esempio n. 5
0
 public function inferFile(GClass $class)
 {
     if ($class->getNamespace() === $this->module->getEntitiesNamespace()) {
         $file = $this->module->getEntitiesPath()->getFile($class->getClassName() . '.php');
     } else {
         $file = Code::mapClassToFile($class->getFQN(), $this->module->getProject()->dir('lib'));
     }
     return $file;
 }
Esempio n. 6
0
 public function testNewInstanceWithoutConstructor()
 {
     $gClass = new GClass('MyConstructorThrowsExceptionClass');
     $gClass->setNamespace(__NAMESPACE__);
     $instance = $gClass->newInstance(array(), GClass::WITHOUT_CONSTRUCTOR);
     $this->assertInstanceOf($gClass->getFQN(), $instance);
     $this->assertTrue($instance->checkProperty);
 }
 public static function missingController(GClass $controllerClass, $exception)
 {
     return new static(sprintf("Controller der Klasse: '%s' nicht gefunden. " . $exception->getMessage(), $controllerClass->getFQN()));
 }
Esempio n. 8
0
 public function removeUsedClass(GClass $class)
 {
     if (array_key_exists($fqn = $class->getFQN(), $this->usedClasses)) {
         unset($this->usedClasses[$fqn]);
     }
     return $this;
 }
Esempio n. 9
0
 public function getFQN()
 {
     return $this->gClass->getFQN();
 }
Esempio n. 10
0
 protected function resolveTaskDependency(GParameter $parameter, GClass $gClass)
 {
     // zuerst nach Name
     switch ($parameter->getName()) {
         case 'targetProject':
         case 'sourceProject':
         case 'target':
         case 'hostName':
         case 'vhostName':
         case 'baseUrl':
         case 'changelog':
         case 'webforgeContainer':
             $getter = 'get' . ucfirst($parameter->getName());
             return $this->{$getter}();
         default:
             if (!$parameter->isOptional()) {
                 throw new \Psc\Exception('Dependency in ' . $gClass->getFQN() . ' ' . $parameter->getName() . ' kann nicht gelöst werden.');
             } else {
                 return $parameter->getDefault();
             }
     }
 }
Esempio n. 11
0
 /**
  * @return Psc\Code\Generate\GClass
  */
 public function getControllerClass($controllerName, $check = TRUE)
 {
     if (array_key_exists($controllerName, $this->controllerClasses)) {
         $gClass = new GClass($this->controllerClasses[$controllerName]);
         $this->log(sprintf("Ueberschreibe Klasse %s fuer ControllerName: %s.", $gClass->getFQN(), $controllerName), 5);
     } else {
         $gClass = new GClass();
         $gClass->setClassName($controllerName . 'Controller');
         $gClass->setNamespace($this->getControllersNamespace());
         $this->log(sprintf("Klasse %s für ControllerName: '%s' mit Controllernamespace generiert.", $gClass->getFQN(), $controllerName), 5);
     }
     try {
         if ($check && !$gClass->exists()) {
             // autoloads
             throw new \Psc\Exception('Klasse existiert nicht');
         }
     } catch (\Exception $e) {
         // sieht so kompliizert aus, damit noch mehr exceptions gecatched werden als diese unsere eigene
         throw ControllerRouteException::missingController($gClass, $e);
     }
     return $gClass;
 }