protected function getComposite()
 {
     $event = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $schema = new SchemaNode('schema', $event);
     $formatter = $this->getMockBuilder('Faker\\Tests\\Engine\\Common\\Formatter\\Mock\\MockFormatter')->disableOriginalConstructor()->getMock();
     $tableA = new TableNode('tableA', $event);
     $columnA1 = new ColumnNode('columnA1', $event);
     $columnA2 = new ColumnNode('columnA2', $event);
     $tableB = new TableNode('tableB', $event);
     $columnB1 = new ColumnNode('columnB1', $event);
     $columnB2 = new ColumnNode('columnB2', $event);
     $tableC = new TableNode('tableC', $event);
     $columnC1 = new ColumnNode('columnC1', $event);
     $columnC2 = new ColumnNode('columnC2', $event);
     $fkc1 = new ForeignKeyNode('fkc1', $event);
     $fmNode = new FormatterNode('fmnode', $event, $formatter);
     $fkc1->setOption('foreignTable', $tableA->getId());
     $fkc1->setOption('foreignColumn', $columnA1->getId());
     $columnC2->addChild($fkc1);
     $tableC->addChild($columnC1);
     $tableC->addChild($columnC2);
     $tableB->addChild($columnB1);
     $tableB->addChild($columnB2);
     $tableA->addChild($columnA1);
     $tableA->addChild($columnA2);
     $schema->addChild($tableA);
     $schema->addChild($tableB);
     $schema->addChild($tableC);
     $schema->addChild($fmNode);
     return $schema;
 }
Esempio n. 2
0
 public function testTypeInterfaceProperties()
 {
     $id = 'fk_table_1';
     $event = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $node = new ColumnNode($id, $event);
     $utilities = $this->getMock('Faker\\Components\\Engine\\Common\\Utilities');
     $generator = $this->getMock('PHPStats\\Generator\\GeneratorInterface');
     $locale = $this->getMock('Faker\\Locale\\LocaleInterface');
     $node->setUtilities($utilities);
     $node->setLocale($locale);
     $node->setGenerator($generator);
     $this->assertEquals($utilities, $node->getUtilities());
     $this->assertEquals($locale, $node->getLocale());
     $this->assertEquals($generator, $node->getGenerator());
 }
Esempio n. 3
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;
 }