public function testBuildMetaSetter() { $builder = new EntityBuilder('Person', $this->module); $builder->createDefaultId(); $builder->createProperty('email', $this->createType('Email')); $builder->createProperty('name', $this->createType('String')); $builder->createProperty('firstName', $this->createType('String')); $builder->createProperty('birthday', $this->createType('DateTime')); $builder->buildSetMetaGetter(); $class = $builder->getGClass(); $this->assertTrue($class->hasMethod('getSetMeta')); $metaGet = $class->getMethod('getSetMeta'); //attention: fragile test here $metaGetPHP = <<<'PHP' public static function getSetMeta() { return new \Psc\Data\SetMeta(array( 'id' => new \Webforge\Types\IdType(), 'email' => new \Webforge\Types\EmailType(), 'name' => new \Webforge\Types\StringType(), 'firstName' => new \Webforge\Types\StringType(), 'birthday' => new \Webforge\Types\DateTimeType(), )); } PHP; $this->assertEquals($metaGetPHP, $metaGet->php()); }
protected function execute(InputInterface $input, OutputInterface $output) { $overwrite = $input->getOption('overwrite') ? EntityBuilder::OVERWRITE : NULL; $module = $this->getDoctrineModule(); $builder = new EntityBuilder($input->getArgument('name'), $module); $entity = $input->getOption('with-entity') != 'false'; $builder->setWithRepository($repo = $input->getOption('with-repository') != 'false'); if ($input->getOption('version1')) { $builder->buildDefault(); } else { $builder->buildDefaultV2(); } if ($entity) { if ($table = $input->getArgument('tableName')) { $builder->setTableName($table); } $file = $builder->write(NULL, $overwrite); $output->writeLn('Entity in Datei: "' . $file . '" geschrieben'); } if ($repo) { $repoFile = $builder->writeRepository(NULL, $overwrite); $output->writeLn('EntityRepository in Datei: "' . $repoFile . '" geschrieben'); } return 0; }
protected function assertCommonRelation(EntityBuilder $builder, $property, $annotationName, $targetEntity) { $this->assertTrue($builder->hasProperty($property), 'Builder hat property: ' . $property . ' nicht.'); $property = $builder->getProperty($property); $this->assertNotNull($property->getDocBlock(), 'DocBlock des Properties: ' . $property->getName() . ' ist nicht gesetzt'); $this->assertInstanceOf('Webforge\\Types\\Type', $type = $property->getType(), 'Type des Properties: ' . $property->getName() . ' ist nicht gesetzt'); if ($type->getName() === 'PersistentCollection') { $innerType = $type->getType(); $this->assertInstanceof('Webforge\\Types\\ObjectType', $innerType); $this->assertEquals($targetEntity, $innerType->getClass()->getFQN()); } elseif ($type->getName() === 'Entity') { $this->assertEquals($targetEntity, $type->getClass()->getFQN()); } else { $this->fail('Type (' . $type->getName() . ') ist weder Collection noch Object für Property: ' . $property->getName()); } $relationAnnotation = $this->assertHasDCAnnotation($property->getDocBlock(), $annotationName); $this->assertEquals($targetEntity, $relationAnnotation->targetEntity, 'Target Entity stimmt nicht überein'); return $relationAnnotation; }
public function getDefaultNamespace() { $eb = new EntityBuilder('notRelevant', $this->module, $this->classWriter); return $eb->getDefaultNamespace(); }