Ejemplo n.º 1
0
 public function testToXml()
 {
     $id = 'column_1';
     $generate = 100;
     $event = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $type = $this->getMockBuilder('Doctrine\\DBAL\\Types\\Type')->disableOriginalConstructor()->getMock();
     $type->expects($this->once())->method('getName')->will($this->returnValue('integer'));
     $column = new ColumnNode($id, $event);
     $column->setDBALType($type);
     $child_a = $this->getMockBuilder('Faker\\Tests\\Engine\\XML\\Mock\\MockNode')->disableOriginalConstructor()->getMock();
     $child_a->expects($this->once())->method('toXml')->will($this->returnValue('<type></type>'));
     $column->addChild($child_a);
     $xml = $column->toXml();
     $this->assertContains('<column name="column_1" type="integer">', $xml);
     $this->assertContains('<type></type>', $xml);
     $this->assertContains('</column>', $xml);
 }
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;
 }