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()); }
public function createEntityBuilder($entityName) { if ($entityName instanceof ClassInterface) { $entityClass = $entityName; } else { $entityClass = new GClass($this->getDefaultNamespace() . '\\' . ltrim($entityName, '\\')); } $this->originalEntityClass = $entityClass; $this->originalEntityName = $entityClass->getClassName(); $compiledEntityClass = clone $entityClass; $compiledEntityClass->setClassName('Compiled' . ucfirst($this->originalEntityName)); $eb = new EntityBuilder($compiledEntityClass, $this->module, $this->classWriter, NULL, $this->getLanguages()); $file = $eb->inferFile($eb->getGClass()); if ($file->exists()) { $file->delete(); } return $eb; }