Esempio n. 1
0
 protected function createType($typeDef)
 {
     if (mb_strpos($typeDef, '\\') !== FALSE) {
         $typeDef = sprintf('Object<%s>', $typeDef);
     }
     return Type::create($typeDef);
 }
Esempio n. 2
0
 /**
  * $this->invalidArgument(1, $param1, 'PositiveInteger', __FUNCTION__);
  * @param string|Type $expected der Type oder ein String der den Typ beschreibt
  * @cc-ignore
  */
 protected function invalidArgument($num, $actual, $expected, $function)
 {
     $class = Code::getClass($this);
     $namespace = Code::getNamespace($class);
     $context = $class . '::' . $function . '()';
     $expandType = function ($type) use($class, $namespace) {
         if (is_string($type)) {
             $type = Type::create($type);
             if ($type instanceof ObjectType) {
                 $type->expandNamespace($namespace);
             }
         }
         return $type;
     };
     if (is_array($expected)) {
         $composite = Type::create('Composite');
         foreach ($expected as $type) {
             $composite->addComponent($expandType($type));
         }
         $expected = $composite;
     } else {
         $expected = $expandType($expected);
     }
     return Exception::invalidArgument($num, $context, $actual, $expected);
 }
Esempio n. 3
0
 public function testConstruct()
 {
     $objectExporter = new ObjectExporter();
     $t = function ($type) {
         return Type::create($type);
     };
     $set = new Set();
     // set implements Walkable
     $set->set('name', 'oids_pages', $t('String'));
     $j1 = new Set();
     $j1->set('name', 'oid', $t('String'));
     $j1->set('referencedColumnName', 'oid', $t('String'));
     $j1->set('onDelete', 'cascade', $t('String'));
     $j2 = new Set();
     $j2->set('name', 'page_id', $t('String'));
     $j2->set('referencedColumnName', 'id', $t('String'));
     $j2->set('onDelete', 'cascade', $t('String'));
     $set->set('joinColumns', array($j1, $j2), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $set->set('inverseJoinColumns', array($j2, $j1), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $this->assertInstanceOf('stdClass', $object = $objectExporter->walkWalkable($set));
     $this->assertInternalType('array', $object->joinColumns);
     $this->assertInternalType('array', $object->inverseJoinColumns);
     $this->assertInstanceOf('stdClass', $object->joinColumns[0]);
     $this->assertInstanceOf('stdClass', $object->inverseJoinColumns[0]);
 }
Esempio n. 4
0
 public static function Column($name, $type, $label = NULL)
 {
     if (is_string($type)) {
         $type = Type::create($type);
     }
     return new Column($name, $type, $label);
 }
Esempio n. 5
0
 public function getWalkableType($field)
 {
     if ($field === 'date') {
         return Type::create('Integer');
     } elseif ($field === 'timezone') {
         return Type::create('String');
     }
 }
 public function testAddProperty()
 {
     $cb = $this->classBuilder;
     $cb->addProperty('thumb')->setType(Type::create('Image'))->addProperty('image')->setType(new ImageType())->addProperty('text')->setType(MarkupTextType::create())->addProperty('link')->setType(Type::create('Link'));
     $this->assertCount(4, $cb->getProperties());
     $this->assertInstanceof($this->cProperty, $cb->getProperty('image'));
     return $cb;
 }
Esempio n. 7
0
 public function testRespectsTypeValidationRule()
 {
     $c = $this->createComponent();
     $typeMock = $this->getMock('Webforge\\Types\\EnumType', array('getValidatorRule'), array(Type::create('String'), array('v1', 'v2')));
     $typeMock->expects($this->once())->method('getValidatorRule')->with($this->isInstanceOf('Psc\\Data\\Type\\TypeRuleMapper'));
     $c->setType($typeMock);
     $c->init();
 }
 public function __construct($propertyPlural, $propertySingular, $itemType = NULL)
 {
     $this->propertyPlural = $propertyPlural;
     $this->propertySingular = $propertySingular;
     $this->collectionType = Type::create('Array');
     if (isset($itemType)) {
         $this->setItemType(Type::create($itemType));
     }
 }
Esempio n. 9
0
 public function testImplementationInnerTypeConstruct()
 {
     $type = Type::create('Collection', CollectionType::DOCTRINE_ARRAY_COLLECTION, new ObjectType(new GClass('Psc\\Doctrine\\Entity')));
     $this->assertEquals('Doctrine\\Common\\Collections\\ArrayCollection', $type->getClass()->getFQN());
     $this->assertTrue($type->isTyped());
     $this->assertInstanceOf('Webforge\\Types\\ObjectType', $type->getType());
     $this->assertEquals('Psc\\Doctrine\\Entity', $type->getType()->getClassFQN());
     return $type;
 }
Esempio n. 10
0
 public static function provideToString()
 {
     $tests = array();
     $test = function ($expectedValue, $value, $type) use(&$tests) {
         $tests[] = array($expectedValue, $value, Type::create($type));
     };
     $test('21.11.1984 00:02', new \Psc\DateTime\DateTime('21.11.1984 00:02:02'), 'DateTime');
     $test('21.11.1984', new \Psc\DateTime\Date('21.11.1984'), 'Date');
     $test('eins, zwei, drei', new \Psc\Data\ArrayCollection(array('eins', 'zwei', 'drei')), 'Collection');
     return $tests;
 }
Esempio n. 11
0
 public static function provideMappings()
 {
     $mapper = new TypeRuleMapper();
     $test = function ($type, $rule) use(&$tests, $mapper) {
         $type = WebforgeType::create($type);
         $tests[] = array($mapper->createRule($rule), $type);
     };
     $test('Id', 'Psc\\Form\\IdValidatorRule');
     $test('String', 'Psc\\Form\\NesValidatorRule');
     return $tests;
 }
Esempio n. 12
0
 /**
  * Wandelt einen Doctrine Type in einen Psc Type um
  * 
  * @return Webforge\Types\Type
  */
 public function getPscType($dcTypeConstant)
 {
     if ($dcTypeConstant === NULL) {
         throw new TypeConversionException('dcTypeConstant kann nicht NULL sein');
     }
     $flip = array_flip($this->casts);
     if (!array_key_exists($dcTypeConstant, $flip)) {
         throw TypeConversionException::typeTarget('Doctrine-Type: ' . $dcTypeConstant, 'Psc-Type');
     }
     return Type::create($flip[$dcTypeConstant]);
 }
Esempio n. 13
0
 public static function provideExportException()
 {
     $tests = array();
     $test = function ($type) use(&$tests) {
         if (!$type instanceof Type) {
             $type = Type::create($type);
         }
         $tests[] = array($type);
     };
     $test(new \Psc\Data\Type\FailingTestType());
     return $tests;
 }
Esempio n. 14
0
 public static function provideTestMapping()
 {
     $tests = array();
     $test = function ($type, $expectedComponent) use(&$tests) {
         $type = Type::create($type);
         $tests[] = array($expectedComponent, $type);
     };
     $test('String', 'TextField');
     $test('Email', 'EmailField');
     $test('DateTime', 'DateTimePicker');
     $test('Date', 'DatePicker');
     // Mapped Component
     $test('SmallInteger', 'SmallIntegerField');
     $test('Birthday', 'BirthdayPicker');
     return $tests;
 }
Esempio n. 15
0
 public function createWalkable()
 {
     $t = function ($type) {
         return Type::create($type);
     };
     $set = new Set();
     // set implements Walkable
     $set->set('name', 'oids_pages', $t('String'));
     $j1 = new Set();
     $j1->set('name', 'oid', $t('String'));
     $j1->set('referencedColumnName', 'oid', $t('String'));
     $j1->set('onDelete', 'cascade', $t('String'));
     $j2 = new Set();
     $j2->set('name', 'page_id', $t('String'));
     $j2->set('referencedColumnName', 'id', $t('String'));
     $j2->set('onDelete', 'cascade', $t('String'));
     $set->set('joinColumns', array($j1, $j2), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $set->set('inverseJoinColumns', array($j2, $j1), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     return $set;
 }
Esempio n. 16
0
 public static function provideMappings()
 {
     $ruleMapper = new ComponentRuleMapper();
     $tests = array();
     $test = function ($component, $rule) use(&$tests, $ruleMapper) {
         $tests[] = array($ruleMapper->createRule($rule), $component);
     };
     // delegates to typeRuleMapper
     $component = new IntegerField();
     $component->setType(Type::create('Id'));
     $test($component, 'Psc\\Form\\IdValidatorRule');
     $component = new TextField();
     $component->setType(Type::create('String'));
     $test($component, 'Psc\\Form\\NesValidatorRule');
     // eigene Componenten-Rules
     $component = new DatePicker();
     $component->init();
     $test($component, 'Psc\\Form\\DateValidatorRule');
     return $tests;
 }
Esempio n. 17
0
 protected static function createData(array $data, $spec)
 {
     $set = new Data();
     $f = function ($field, $type = 'String') use(&$set) {
         $set->setFieldType($field, Type::create($type));
     };
     if ($spec === 'person') {
         $f('firstName');
         $f('name');
         $f('telephone');
         $f('company.title');
         $f('address.street');
         $f('address.zip', 'PositiveInteger');
         $f('address.countryCode');
         $f('address.city');
         $f('taxId');
     } elseif ($spec === 'recipient') {
         $f('company.title');
         $f('company.department');
         $f('company.co');
         $f('address.street');
         $f('address.zip', 'PositiveInteger');
         $f('address.countryCode');
         $f('address.city');
     } elseif ($spec === 'invoice') {
         $f('dateTime', 'DateTime');
         $f('labelId');
         $f('place');
         // wenn nicht gesetzt wird person address city genommen
         $f('performancePeriod');
         $f('text', 'MarkupText');
     } else {
         throw new \Psc\Exception('unbekannte spec: ' . $spec);
     }
     // validiert ein bissl
     foreach ($data as $field => $value) {
         $set->set($field, $value);
     }
     return $set;
 }
 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');
 }
Esempio n. 19
0
 public function addControlColumn()
 {
     return $this->createColumn('ctrl', Type::create('String'), self::EMPTY_LABEL, array(), function (Entity $entity) {
         return \Psc\UI\fHTML::checkbox('egp-ctrl[]', FALSE, $entity->getIdentifier())->addClass('\\Psc\\identifier-checkbox');
     });
 }
Esempio n. 20
0
 public function setUp()
 {
     $this->chainClass = 'Psc\\Data\\Table';
     parent::setUp();
     $this->table = new Table(array(Table::Column('num', Type::create('Integer')), Table::Column('ident', Type::create('String')), Table::Column('Sound', Type::create('String'))));
 }
Esempio n. 21
0
 /**
  * Erstellt einen neuen LType - Wrapper
  * 
  * der Name des Types muss ein bestehender Webforge\Types\$nameType sein
  * siehe auch Webforge\Types\Type::create()
  */
 public function __construct($typeName)
 {
     $this->type = Type::create($typeName);
 }
Esempio n. 22
0
 protected function getRandomData($typeName)
 {
     if (!$typeName instanceof Type) {
         $type = Type::create($typeName);
     } else {
         $type = $typeName;
     }
     $generator = $this->createRandomGenerator();
     return $generator->generateData($type);
 }
Esempio n. 23
0
 public function createDefaultId()
 {
     $this->addProperty('id')->setType(Type::create('Id'))->createDocBlock()->addAnnotation(Annotation::createDC('Id'))->addAnnotation(Annotation::createDC('GeneratedValue'))->addAnnotation(Annotation::createDC('Column', array('type' => 'integer')));
     $this->generateGetter($this->getProperty('id'));
     $this->generateGetter($this->getProperty('id'), 'getIdentifier', self::INHERIT);
     // weil uns da gerade die abstract method getIdentifier reinfunkt (fixme)
     $this->generateSetter($this->getProperty('id'), 'setIdentifier', self::INHERIT);
     $this->identifier = 'id';
     return $this;
 }
Esempio n. 24
0
 /**
  * Erstellt aus dem Request und dem FormPanel ein Set mit allen FormularDaten
  *
  * man könnte sich hier auch mal vorstellen die formulardaten im set aufzusplitten
  * Sicherheit: alle Felder die nicht registriert sind durch Componenten oder den Formpanel (getControlFields) schmeissen hier eine Exception
  */
 public function createFormDataSet(FormData $requestData, EntityFormPanel $panel, Entity $entity)
 {
     $meta = $entity->getSetMeta();
     // wir müssen die Spezial-Felder vom EntityFormPanel hier tracken
     foreach ($panel->getControlFields() as $field) {
         $meta->setFieldType($field, Type::create('String'));
     }
     // sonderfeld disabled wird ignored
     $meta->setFieldType('disabled', Type::create('Array'));
     try {
         $set = new Set((array) $requestData, $meta);
     } catch (\Psc\Data\FieldNotDefinedException $e) {
         throw \Psc\Exception::create("In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s).", implode('.', $e->field), implode(', ', $e->avaibleFields));
     }
     return $set;
 }
Esempio n. 25
0
 public function testInvalidArgumentException()
 {
     $this->assertEquals(Exception::invalidArgument(1, 'Psc\\ASimpleObjectClass::doSomething()', 'wrongValue', Type::create('Composite')->setComponents(Type::create('Integer'), Type::create('Object<Psc\\NiceClass>'))), $this->simpleObject->doSomething('wrongValue'));
 }
Esempio n. 26
0
 public function createType($typeName)
 {
     if ($typeName instanceof Type) {
         return $typeName;
     }
     return Type::create($typeName);
 }
Esempio n. 27
0
 public function testProcessSetWithOnProcessField()
 {
     $expectedContent = 'das ist der neue Content';
     $expectedTitle = 'das ist der neue Title';
     $set = new Set(array('content' => 'das ist der Content, der nicht zu sehen sein soll', 'title' => $expectedTitle), new SetMeta(array('content' => Type::create('String'), 'title' => Type::create('String'))));
     $that = $this;
     $article = $this->article;
     $this->processor->onProcessSetField('content', function ($entity, $field, $value, $type) use($that, $article, $expectedContent) {
         $that->assertSame($article, $entity);
         $that->assertEquals('content', $field);
         $that->assertInstanceOf('Webforge\\Types\\StringType', $type);
         $entity->callSetter($field, $expectedContent);
     });
     $this->processor->processSet($set);
     $this->assertEquals($expectedContent, $this->article->getContent());
     $this->assertEquals($expectedTitle, $this->article->getTitle());
 }
 public function testUpdateIndex_WrongUniqueConstraint()
 {
     $this->setExpectedException('InvalidArgumentException');
     $this->validator->updateIndex(new UniqueConstraint('test', array('episode_id' => Type::create('Integer'))), array());
 }