Example #1
0
 public function create($overwrite = false)
 {
     try {
         $this->class->elevateClass();
         // @todo das mal konfigurieren und fixen
     } catch (\Exception $e) {
         $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage());
     } catch (\Psc\Code\Generate\ReflectionException $e) {
         $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage());
     }
     $class = new GClass();
     $class->setName($this->class->getClassName() . 'Test');
     $class->setNamespace($this->class->getNamespace());
     $class->setParentClass($this->testClass);
     $writer = new ClassWriter();
     $writer->setClass($class);
     $class = $this->createStub($class);
     $file = $this->getTestFile();
     if (isset($this->createCallback)) {
         $class = call_user_func($this->createCallback, $class, $this, $writer, $file);
     }
     $writer->addImport($this->class);
     // not really necessary (weil ist ja derselbe NS, aber who knows)
     $file->getDirectory()->create();
     $writer->write($file, array(), $overwrite);
     return $file;
 }
Example #2
0
 public function testMethodOrdering()
 {
     $gClass = new GClass(__NAMESPACE__ . '\\OrderedMethods');
     $gClass->setParentClass(new GClass(__NAMESPACE__ . '\\MyDocTestClass'));
     $gClass->createMethod('getIdentifier');
     $gClass->createMethod('getObjectName');
     $gClass->createMethod('setLabel', array(new GParameter('label')));
     $gClass->createMethod('getLabel');
     $gClass->addMethod(new GMethod('__construct'), GClass::PREPEND);
     $classWriter = new ClassWriter($gClass);
     $classWriter->write($out = $this->newFile('class.OrderedMethods.php'), array(), ClassWriter::OVERWRITE);
     require $out;
     $gClass = GClass::factory(__NAMESPACE__ . '\\OrderedMethods');
     $getMethodNames = function (array $methods) {
         $methodNames = array();
         foreach ($methods as $method) {
             $methodNames[] = $method->getName();
         }
         return $methodNames;
     };
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel'), $getMethodNames($gClass->getMethods()));
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel', 'getName'), $getMethodNames($gClass->getAllMethods()));
     // parent methods behind
     $gClass->setMethodOrder($gClass->getMethod('getLabel'), 1);
     $this->assertEquals(array('__construct', 'getLabel', 'getIdentifier', 'getObjectName', 'setLabel'), $getMethodNames($gClass->getMethods()));
 }
 public function testMethodGenerationAcceptance()
 {
     $gClass = new GClass('ToBeStubbedClass');
     $gClass->setParentClass(new GClass(__NAMESPACE__ . '\\StubTestAbstractClass'));
     $gClass->addInterface(new GClass(__NAMESPACE__ . '\\AnInterface'));
     $gClass->createAbstractMethodStubs();
     $this->test->gClass($gClass)->hasMethod('getName')->hasMethod('implementIt')->hasMethod('implementItFromParent')->hasMethod('generateDependency', array('deps', 'gClass'));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $overwrite = $input->getOption('overwrite') ? ClassWriter::OVERWRITE : NULL;
     $controllerName = $input->getArgument('name');
     $entityClass = $this->getDoctrineModule()->getEntityName($controllerName);
     $gClass = new GClass();
     $gClass->setClassName($controllerName . 'Controller');
     $gClass->setNamespace($this->getProject()->getNamespace() . '\\Controllers');
     // siehe auch EntityService
     $gClass->setParentClass(new GClass('Psc\\CMS\\Controller\\AbstractEntityController'));
     $classBuilder = new ClassBuilder($gClass);
     $classBuilder->createProtectedMethod('setUp', array(), array("parent::setUp();"));
     $classBuilder->createMethod('getEntityName', array(), array(sprintf("return '%s';", $entityClass)));
     $imports = array(new GClass($entityClass));
     $classWriter = new ClassWriter();
     $classWriter->setClass($gClass);
     $classWriter->write($file = $this->getProject()->getClassFile($gClass), $imports, $overwrite);
     $output->writeLn('Controller in Datei: "' . $file . '" geschrieben');
     return 0;
 }
Example #5
0
    public function testWithGClass()
    {
        $gClass = new GClass('\\ePaper42\\Entities\\Journal');
        $gClass->setParentClass(new GClass('\\Psc\\XML\\Object'));
        $gClass->createProperty('title')->createDocBlock("Titel des Objektes (Name der Zeitschrift)\n")->addSimpleAnnotation('xml:XmlElement');
        $gClass->createProperty('key')->createDocBlock("Key des Objektes\n")->addSimpleAnnotation('xml:XmlElement');
        $gClass->createProperty('volumes')->createDocBlock("Volumes des Journals (Jahreszahlen)\n")->addSimpleAnnotation('xml:XmlElement', array('name' => 'volumne', 'wrapper' => 'volumeList', 'type' => 'ePaper42\\Entities\\Volume'));
        $classCode = <<<'CLASS_END'
class Journal extends \Psc\XML\Object {
  
  /**
   * Titel des Objektes (Name der Zeitschrift)
   * 
   * @xml:XmlElement
   */
  protected $title;
  
  /**
   * Key des Objektes
   * 
   * @xml:XmlElement
   */
  protected $key;
  
  /**
   * Volumes des Journals (Jahreszahlen)
   * 
   * @xml:XmlElement(name="volumne", wrapper="volumeList", type="ePaper42\Entities\Volume")
   */
  protected $volumes;
}
CLASS_END;
        //file_put_contents('D:\fixture.txt',$classCode);
        //file_put_contents('D:\actual.txt',$gClass->php());
        $this->assertEquals($classCode, $gClass->php());
    }