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 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;
 }
 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
 /**
  * @return File
  */
 public function writeRepository(File $file = NULL, $overwrite = NULL)
 {
     $gClass = $this->getRepositoryGClass();
     $this->classWriter->setClass($gClass);
     if (!isset($file)) {
         $autoLoadRoot = $this->module->getEntitiesPath()->sub(str_repeat('../', count(explode('\\', $this->module->getEntitiesNamespace()))))->resolvePath();
         $file = Code::mapClassToFile($gClass->getFQN(), $autoLoadRoot);
     }
     $this->classWriter->write($file, array(), $overwrite);
     $this->classWriter->syntaxCheck($file);
     return $file;
 }
 public function testAcceptance()
 {
     $gClass = new GClass(__NAMESPACE__ . '\\Table' . uniqid('table'));
     $this->extension->compile($gClass);
     // quicktest
     $this->test->gClass($gClass)->hasProperty('columns')->hasMethod('getColumns')->hasMethod('setColumns', array('columns'))->hasMethod('removeColumn', array('column'))->hasMethod('getColumn', array('key'))->hasMethod('addColumn', array('column'))->hasMethod('hasColumn', array('column'));
     // acceptance
     $classWriter = new ClassWriter($gClass);
     $classWriter->write($file = $this->newFile('out.php'), array(), ClassWriter::OVERWRITE);
     require $file;
     $table = $gClass->newInstance();
     $c1 = new Column('c1', Type::create('String'), 'Spalte 1');
     $c2 = new Column('c2', Type::create('Integer'), 'Spalte 2');
     $this->assertInternalType('array', $table->getColumns(), 'getColumns gibt keinen Array zurück');
     $this->assertCount(0, $table->getColumns());
     $table->setColumns(array($c1, $c2));
     $this->assertEquals(array($c1, $c2), $table->getColumns(), 'setColumns() funktioniert nicht richtig');
     $this->assertTrue($table->hasColumn($c1), 'hasColumn(c1) gibt nicht true zurück');
     $this->assertTrue($table->hasColumn($c2), 'hasColumn(c2) gibt nicht true zurück');
     $table->removeColumn($c1);
     $this->assertEquals(array($c2), $table->getColumns(), 'c2 wurde nicht entfernt');
     $this->assertFalse($table->hasColumn($c1), 'hasColumn(c1) muss false sein nach removen');
     $this->assertTrue($table->hasColumn($c2), 'hasColumn(c2) muss noch true sein nach dem removen von c1');
 }
Example #7
0
        }
    }
    $class->generateGetters();
    $class->generateSetters();
    $class->generateDocBlocks();
    $optionsCode = array();
    $optionsCode[] = '$options = new \\stdClass;';
    $optionsCode[] = sprintf('foreach (%s as $option) {', $class->getCodeWriter()->exportList($properties));
    $optionsCode[] = sprintf('  if ($this->$option !== "%s") {', $undefined);
    $optionsCode[] = sprintf('    $options->$option = $this->$option;');
    $optionsCode[] = '  }';
    $optionsCode[] = '}';
    $optionsCode[] = 'return $options;';
    $class->createMethod('getWidgetOptions', array(), $optionsCode)->createDocBlock()->setSummary('Gibt alle gesetzten Optionen des Widgets zurück')->addSimpleAnnotation('return stdClass');
    $class->getClassDocBlock()->addSimpleAnnotation('compiled jqx-widget-specification console-command on ' . date('d.m.Y H:i'));
    $cw = new ClassWriter($gClass = $class->getGClass());
    $cw->setUseStyle(ClassWriter::USE_STYLE_LINES);
    $phpFile = $command->getProject()->getClassFile($gClass);
    $cw->write($phpFile, array(), $overwrite = ClassWriter::OVERWRITE);
    $output->writeln($phpFile . ' written.');
});
$createCommand('tests:build-from-json', array($arg('file')), function ($input, $output, $command) {
    $jsonc = JSONConverter::create();
    $root = Dir::factoryTS(__DIR__)->sub('../');
    $json = $root->getFile($input->getArgument('file'))->getContents();
    $json = '[' . str_replace('}{', '},{', $json) . ']';
    try {
        $report = $jsonc->parse($json);
    } catch (\Webforge\Common\JS\JSONParsingException $e) {
        $parser = new JsonParser();
        $parsingException = $parser->lint($root->getFile('output.json')->getContents());
Example #8
0
 public function setUp()
 {
     $this->classWriter->setUseStyle(ClassWriter::USE_STYLE_LINES);
     // "use" für jeden import davorschreiben
 }
Example #9
0
 public function testSyntaxCheckSuccess()
 {
     $writer = new ClassWriter();
     $this->assertTrue($writer->syntaxCheck(new File(__FILE__), 'return'));
 }