Ejemplo n.º 1
0
 public function testValidationCallsChildren()
 {
     $id = 'schema_1';
     $event = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $column = new ColumnNode($id, $event);
     $childA = $this->getMockBuilder('Faker\\Tests\\Engine\\XML\\Mock\\MockNode')->disableOriginalConstructor()->getMock();
     $childA->expects($this->once())->method('validate');
     $column->addChild($childA);
     $column->setOption('name', 'schemaNode');
     $column->setOption('generatorSeed', 100);
     $column->setOption('randomGenerator', 'srand');
     $column->setOption('type', 'integer');
     $column->validate();
     $this->assertEquals(100, $column->getOption('generatorSeed'));
     $this->assertEquals('srand', $column->getOption('randomGenerator'));
 }
Ejemplo n.º 2
0
 public function addColumn($name, array $options = array())
 {
     # schema and table exist
     if (!$this->head instanceof TableNode) {
         throw new EngineException('Can not add new column without first setting a table and schema');
     }
     if (isset($options['type']) === false) {
         throw new EngineException('Column requires a doctrine type');
     } else {
         if (Type::hasType($options['type']) === false) {
             throw new EngineException('The doctrine DBAL Type::' . $dbalTypeName . ' does not exist');
         }
     }
     if (isset($options['name']) === false) {
         $options['name'] = $name;
     }
     # merge options with defaults
     $options = array_merge(array('locale' => $this->head->getOption('locale')), $options);
     # create new column
     $id = $name;
     $column = new ColumnNode($id, $this->eventDispatcher);
     # bind the doctine column type
     $column->setDBALType(Type::getType($options['type']));
     # set the options
     foreach ($options as $optionKey => $optionValue) {
         $column->setOption($optionKey, $optionValue);
     }
     # add the column to the table
     $this->head->addChild($column);
     $this->head = $column;
     return $this;
 }