/** * @return void */ protected function _before() { $config = new QuickGeneratorConfig(); $table = new Table('Foo'); $column = new Column('testColumn', PropelTypes::INTEGER); $table->addColumn($column); $table->setNamespace('Unit\\Spryker\\Zed\\Propel\\Business\\Builder\\QueryBuilder'); $table->setDatabase(new Database('TestDB', new DefaultPlatform())); foreach ($this->getFilesToGenerate() as $fileName => $builderClass) { $builder = new $builderClass($table); $builder->setGeneratorConfig($config); $this->writePropelFile($builder, $fileName); } }
public function testGetIndexDDLFulltext() { $table = new Table('foo'); $table->setIdentifierQuoting(true); $column1 = new Column('bar1'); $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR')); $table->addColumn($column1); $index = new Index('bar_index'); $index->addColumn($column1); $vendor = new VendorInfo('mysql'); $vendor->setParameter('Index_type', 'FULLTEXT'); $index->addVendorInfo($vendor); $table->addIndex($index); $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)'; $this->assertEquals($expected, $this->getPlatform()->getIndexDDL($index)); }
public function testGetModifyColumnDDLWithChangedTypeAndDefault() { $t1 = new Table('foo'); $c1 = new Column('bar'); $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE')); $c1->getDomain()->replaceSize(2); $t1->addColumn($c1); $t2 = new Table('foo'); $c2 = new Column('bar'); $c2->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE')); $c2->getDomain()->replaceSize(3); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(-100, ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c2); $columnDiff = ColumnComparator::computeDiff($c1, $c2); $expected = <<<END ALTER TABLE foo ALTER COLUMN bar TYPE DOUBLE PRECISION; ALTER TABLE foo ALTER COLUMN bar SET DEFAULT -100; END; $this->assertEquals($expected, $this->getPlatform()->getModifyColumnDDL($columnDiff)); }
public function testCompareSeveralTableDifferences() { $d1 = new Database(); $t1 = new Table('Foo_Table'); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c1->getDomain()->replaceScale(2); $c1->getDomain()->replaceSize(3); $c1->setNotNull(true); $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t1->addColumn($c1); $d1->addTable($t1); $t2 = new Table('Bar'); $c2 = new Column('Bar_Column'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $t2->addColumn($c2); $d1->addTable($t2); $t11 = new Table('Baz'); $d1->addTable($t11); $d2 = new Database(); $t3 = new Table('Foo_Table'); $c3 = new Column('Foo1'); $c3->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c3->getDomain()->replaceScale(2); $c3->getDomain()->replaceSize(3); $c3->setNotNull(true); $c3->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t3->addColumn($c3); $d2->addTable($t3); $t4 = new Table('Bar2'); $c4 = new Column('Bar_Column'); $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $t4->addColumn($c4); $d2->addTable($t4); $t5 = new Table('Biz'); $c5 = new Column('Biz_Column'); $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $t5->addColumn($c5); $d2->addTable($t5); // Foo_Table was modified, Bar was renamed, Baz was removed, Biz was added $dc = new DatabaseComparator(); $dc->setFromDatabase($d1); $dc->setToDatabase($d2); $nbDiffs = $dc->compareTables(); $databaseDiff = $dc->getDatabaseDiff(); $this->assertEquals(4, $nbDiffs); $this->assertEquals(array('Bar' => 'Bar2'), $databaseDiff->getRenamedTables()); $this->assertEquals(array('Biz' => $t5), $databaseDiff->getAddedTables()); $this->assertEquals(array('Baz' => $t11), $databaseDiff->getRemovedTables()); $tableDiff = TableComparator::computeDiff($t1, $t3); $this->assertEquals(array('Foo_Table' => $tableDiff), $databaseDiff->getModifiedTables()); }
public function testRemoveColumnFixesPositions() { $table = new Table(); $col1 = new Column('Foo1'); $table->addColumn($col1); $col2 = new Column('Foo2'); $table->addColumn($col2); $col3 = new Column('Foo3'); $table->addColumn($col3); $this->assertEquals(1, $col1->getPosition()); $this->assertEquals(2, $col2->getPosition()); $this->assertEquals(3, $col3->getPosition()); $this->assertEquals(array(0, 1, 2), array_keys($table->getColumns())); $table->removeColumn($col2); $this->assertEquals(1, $col1->getPosition()); $this->assertEquals(2, $col3->getPosition()); $this->assertEquals(array(0, 1), array_keys($table->getColumns())); }
public function testExcludedTablesWithRenaming() { $dc = new DatabaseComparator(); $this->assertCount(0, $dc->getExcludedTables()); $dc->setExcludedTables(array('foo')); $this->assertCount(1, $dc->getExcludedTables()); $d1 = new Database(); $d2 = new Database(); $t2 = new Table('Bar'); $d2->addTable($t2); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar')); $this->assertFalse($diff); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Baz')); $this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff); $d1 = new Database(); $t1 = new Table('Foo'); $d1->addTable($t1); $d2 = new Database(); $t2 = new Table('Bar'); $d2->addTable($t2); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar', 'Foo')); $this->assertFalse($diff); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Foo')); $this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar')); $this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff); $d1 = new Database(); $t1 = new Table('Foo'); $c1 = new Column('col1'); $t1->addColumn($c1); $d1->addTable($t1); $d2 = new Database(); $t2 = new Table('Foo'); $d2->addTable($t2); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar', 'Foo')); $this->assertFalse($diff); $diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar')); $this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff); }
public function testGetPrimaryKeyDDLCompositeKey() { $table = new Table('foo'); $column1 = new Column('bar1'); $column1->setPrimaryKey(true); $table->addColumn($column1); $column2 = new Column('bar2'); $column2->setPrimaryKey(true); $table->addColumn($column2); $expected = 'PRIMARY KEY ([bar1],[bar2])'; $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table)); }
public function testCompareSeveralColumnDifferences() { $t1 = new Table(); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $c1->setNotNull(false); $t1->addColumn($c1); $c2 = new Column('col2'); $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c2->setNotNull(true); $t1->addColumn($c2); $c3 = new Column('col3'); $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); $t2 = new Table(); $c4 = new Column('col1'); $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c4->getDomain()->replaceScale(2); $c4->getDomain()->replaceSize(3); $c4->setNotNull(true); $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c4); $c5 = new Column('col22'); $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c5->setNotNull(true); $t2->addColumn($c5); $c6 = new Column('col4'); $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR')); $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c6); // col1 was modified, col2 was renamed, col3 was removed, col4 was added $tc = new PropelTableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareColumns(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(4, $nbDiffs); $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns()); $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns()); $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns()); $columnDiff = PropelColumnComparator::computeDiff($c1, $c4); $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns()); }
public function providerForTestPrimaryKeyDDL() { $table = new Table('foo'); $table->setIdentifierQuoting(true); $column = new Column('bar'); $column->setPrimaryKey(true); $table->addColumn($column); return array(array($table)); }
public function providerForTestGetForeignKeysDDL() { $table1 = new Table('foo'); $column1 = new Column('bar_id'); $column1->getDomain()->copy(new Domain('FOOTYPE')); $table1->addColumn($column1); $table2 = new Table('bar'); $column2 = new Column('id'); $column2->getDomain()->copy(new Domain('BARTYPE')); $table2->addColumn($column2); $fk = new ForeignKey('foo_bar_fk'); $fk->setForeignTableCommonName('bar'); $fk->addReference($column1, $column2); $fk->setOnDelete('CASCADE'); $table1->addForeignKey($fk); $column3 = new Column('baz_id'); $column3->getDomain()->copy(new Domain('BAZTYPE')); $table1->addColumn($column3); $table3 = new Table('baz'); $column4 = new Column('id'); $column4->getDomain()->copy(new Domain('BAZTYPE')); $table3->addColumn($column4); $fk = new ForeignKey('foo_baz_fk'); $fk->setForeignTableCommonName('baz'); $fk->addReference($column3, $column4); $fk->setOnDelete('SETNULL'); $table1->addForeignKey($fk); return array(array($table1)); }
protected function addLogColumns(Table $table) { if ('true' === $this->getParameter('created_at') && !$table->hasColumn($this->getParameter('created_at_column'))) { $table->addColumn(array('name' => $this->getParameter('created_at_column'), 'type' => 'TIMESTAMP')); } if ('true' === $this->getParameter('created_by') && !$table->hasColumn($this->getParameter('created_by_column'))) { $table->addColumn(array('name' => $this->getParameter('created_by_column'), 'type' => 'VARCHAR', 'size' => 100)); } if ('true' === $this->getParameter('comment') && !$table->hasColumn($this->getParameter('comment_column'))) { $table->addColumn(array('name' => $this->getParameter('comment_column'), 'type' => 'VARCHAR', 'size' => 255)); } }
public function startElement($parser, $name, $attributes) { $parentTag = $this->peekCurrentSchemaTag(); if (false === $parentTag) { switch ($name) { case 'database': if ($this->isExternalSchema()) { $this->currentPackage = isset($attributes['package']) ? $attributes['package'] : null; if (null === $this->currentPackage) { $this->currentPackage = $this->defaultPackage; } } else { $this->currDB = $this->schema->addDatabase($attributes); } break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('database' === $parentTag) { switch ($name) { case 'external-schema': $xmlFile = isset($attributes['filename']) ? $attributes['filename'] : null; // 'referenceOnly' attribute is valid in the main schema XML file only, // and it's ignored in the nested external-schemas if (!$this->isExternalSchema()) { $isForRefOnly = isset($attributes['referenceOnly']) ? $attributes['referenceOnly'] : null; $this->isForReferenceOnly = null !== $isForRefOnly ? 'true' === strtolower($isForRefOnly) : true; // defaults to TRUE } if ('/' !== $xmlFile[0]) { $xmlFile = realpath(dirname($this->currentXmlFile) . DIRECTORY_SEPARATOR . $xmlFile); if (!file_exists($xmlFile)) { throw new SchemaException(sprintf('Unknown include external "%s"', $xmlFile)); } } $this->parseFile($xmlFile); break; case 'domain': $this->currDB->addDomain($attributes); break; case 'table': if (!isset($attributes['schema']) && $this->currDB->getSchema() && $this->currDB->getPlatform()->supportsSchemas() && false === strpos($attributes['name'], $this->currDB->getPlatform()->getSchemaDelimiter())) { $attributes['schema'] = $this->currDB->getSchema(); } $this->currTable = $this->currDB->addTable($attributes); if ($this->isExternalSchema()) { $this->currTable->setForReferenceOnly($this->isForReferenceOnly); $this->currTable->setPackage($this->currentPackage); } break; case 'vendor': $this->currVendorObject = $this->currDB->addVendorInfo($attributes); break; case 'behavior': $this->currBehavior = $this->currDB->addBehavior($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('table' === $parentTag) { switch ($name) { case 'column': $this->currColumn = $this->currTable->addColumn($attributes); break; case 'foreign-key': $this->currFK = $this->currTable->addForeignKey($attributes); break; case 'index': $this->currIndex = new Index(); $this->currIndex->setTable($this->currTable); $this->currIndex->loadMapping($attributes); break; case 'unique': $this->currUnique = new Unique(); $this->currUnique->setTable($this->currTable); $this->currUnique->loadMapping($attributes); break; case 'vendor': $this->currVendorObject = $this->currTable->addVendorInfo($attributes); break; case 'id-method-parameter': $this->currTable->addIdMethodParameter($attributes); break; case 'behavior': $this->currBehavior = $this->currTable->addBehavior($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('column' === $parentTag) { switch ($name) { case 'inheritance': $this->currColumn->addInheritance($attributes); break; case 'vendor': $this->currVendorObject = $this->currColumn->addVendorInfo($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('foreign-key' === $parentTag) { switch ($name) { case 'reference': $this->currFK->addReference($attributes); break; case 'vendor': $this->currVendorObject = $this->currUnique->addVendorInfo($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('index' === $parentTag) { switch ($name) { case 'index-column': $this->currIndex->addColumn($attributes); break; case 'vendor': $this->currVendorObject = $this->currIndex->addVendorInfo($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('unique' === $parentTag) { switch ($name) { case 'unique-column': $this->currUnique->addColumn($attributes); break; case 'vendor': $this->currVendorObject = $this->currUnique->addVendorInfo($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ($parentTag == 'behavior') { switch ($name) { case 'parameter': $this->currBehavior->addParameter($attributes); break; default: $this->_throwInvalidTagException($parser, $name); } } elseif ('vendor' === $parentTag) { switch ($name) { case 'parameter': $this->currVendorObject->setParameter($attributes['name'], $attributes['value']); break; default: $this->_throwInvalidTagException($parser, $name); } } else { // it must be an invalid tag $this->_throwInvalidTagException($parser, $name); } $this->pushCurrentSchemaTag($name); }
public function testCompareSeveralRenamedSamePrimaryKeys() { $t1 = new Table(); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c1->setNotNull(true); $c1->setPrimaryKey(true); $t1->addColumn($c1); $c2 = new Column('col2'); $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c2->setNotNull(true); $c2->setPrimaryKey(true); $t1->addColumn($c2); $c3 = new Column('col3'); $c3->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c3->setNotNull(true); $c3->setPrimaryKey(true); $t1->addColumn($c3); $t2 = new Table(); $c4 = new Column('col4'); $c4->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c4->setNotNull(true); $c4->setPrimaryKey(true); $t2->addColumn($c4); $c5 = new Column('col5'); $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c5->setNotNull(true); $c5->setPrimaryKey(true); $t2->addColumn($c5); $c6 = new Column('col3'); $c6->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c6->setNotNull(true); $c6->setPrimaryKey(true); $t2->addColumn($c6); // col1 and col2 were renamed $tc = new TableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->comparePrimaryKeys(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(2, $nbDiffs); $this->assertEquals([[$c1, $c4], [$c2, $c5]], $tableDiff->getRenamedPkColumns()); $this->assertEquals([], $tableDiff->getAddedPkColumns()); $this->assertEquals([], $tableDiff->getRemovedPkColumns()); }
public function testHasPlatform() { $column = new Column(); $this->assertFalse($column->hasPlatform()); $table = new Table(); $table->addColumn($column); $this->assertFalse($column->hasPlatform()); $database = new Database(); $database->addTable($table); $this->assertFalse($column->hasPlatform()); $platform = new DefaultPlatform(); $database->setPlatform($platform); $this->assertTrue($column->hasPlatform()); }
protected function addColumn(Table $table, $name) { if (!$table->hasColumn($name)) { $column = new Column($name); // don't know how to define unsigned :( $domain = new Domain('TINYINT', 'tinyint(3) unsigned'); $column->setDomain($domain); $table->addColumn($column); $column_idx_name = $name . '_idx'; if (!$table->hasIndex($column_idx_name)) { $column_idx = new Index($column_idx_name); $column_idx->addColumn(['name' => $column->getName()]); $table->addIndex($column_idx); } } }
public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $c1 = new Column(); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $c2 = new Column(); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); return array(array(PropelColumnComparator::computeDiff($c1, $c2))); }
public function testGetAutoIncrementPrimaryKey() { $column1 = $this->getColumnMock('id', array('primary' => true, 'auto_increment' => true)); $column2 = $this->getColumnMock('title'); $column3 = $this->getColumnMock('isbn'); $table = new Table(); $table->setIdMethod('native'); $table->addColumn($column1); $table->addColumn($column2); $table->addColumn($column3); $this->assertCount(1, $table->getPrimaryKey()); $this->assertTrue($table->hasPrimaryKey()); $this->assertTrue($table->hasAutoIncrementPrimaryKey()); $this->assertSame($column1, $table->getAutoIncrementPrimaryKey()); }
public function testCompareModifiedIndices() { $t1 = new Table(); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $c1->setNotNull(false); $t1->addColumn($c1); $i1 = new Index('Foo_Index'); $i1->addColumn($c1); $t1->addIndex($i1); $t2 = new Table(); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); $c2->getDomain()->replaceSize(3); $c2->setNotNull(true); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c2); $i2 = new Unique('Foo_Index'); $i2->addColumn($c2); $t2->addIndex($i2); $tc = new PropelTableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareIndices(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(1, $nbDiffs); $this->assertEquals(1, count($tableDiff->getModifiedIndices())); $this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices()); }
public function testCompareSeveralRenamedSameColumns() { $t1 = new Table(); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $t1->addColumn($c1); $c2 = new Column('col2'); $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c2->getDomain()->replaceSize(255); $t1->addColumn($c2); $c3 = new Column('col3'); $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); $t2 = new Table(); $c4 = new Column('col4'); $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c4->getDomain()->replaceSize(255); $t2->addColumn($c4); $c5 = new Column('col5'); $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c5->getDomain()->replaceSize(255); $t2->addColumn($c5); $c6 = new Column('col3'); $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c6->getDomain()->replaceSize(255); $t2->addColumn($c6); // col1 and col2 were renamed $tc = new TableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareColumns(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(2, $nbDiffs); $this->assertEquals([[$c1, $c4], [$c2, $c5]], $tableDiff->getRenamedColumns()); $this->assertEquals([], $tableDiff->getAddedColumns()); $this->assertEquals([], $tableDiff->getRemovedColumns()); $this->assertEquals([], $tableDiff->getModifiedColumns()); }
public function testToString() { $tableA = new Table('A'); $tableB = new Table('B'); $diff = new TableDiff($tableA, $tableB); $diff->addAddedColumn('id', new Column('id', 'integer')); $diff->addRemovedColumn('category_id', new Column('category_id', 'integer')); $colFoo = new Column('foo', 'integer'); $colBar = new Column('bar', 'integer'); $tableA->addColumn($colFoo); $tableA->addColumn($colBar); $diff->addRenamedColumn($colFoo, $colBar); $columnDiff = new ColumnDiff($colFoo, $colBar); $diff->addModifiedColumn('foo', $columnDiff); $fk = new ForeignKey('category'); $fk->setTable($tableA); $fk->setForeignTableCommonName('B'); $fk->addReference('category_id', 'id'); $fkChanged = clone $fk; $fkChanged->setForeignTableCommonName('C'); $fkChanged->addReference('bla', 'id2'); $fkChanged->setOnDelete('cascade'); $fkChanged->setOnUpdate('cascade'); $diff->addAddedFk('category', $fk); $diff->addModifiedFk('category', $fk, $fkChanged); $diff->addRemovedFk('category', $fk); $index = new Index('test_index'); $index->setTable($tableA); $index->setColumns([$colFoo]); $indexChanged = clone $index; $indexChanged->setColumns([$colBar]); $diff->addAddedIndex('test_index', $index); $diff->addModifiedIndex('test_index', $index, $indexChanged); $diff->addRemovedIndex('test_index', $index); $string = (string) $diff; $expected = ' A: addedColumns: - id removedColumns: - category_id modifiedColumns: A.FOO: modifiedProperties: renamedColumns: foo: bar addedIndices: - test_index removedIndices: - test_index modifiedIndices: - test_index addedFks: - category removedFks: - category modifiedFks: category: localColumns: from ["category_id"] to ["category_id","bla"] foreignColumns: from ["id"] to ["id","id2"] onUpdate: from to CASCADE onDelete: from to CASCADE '; $this->assertEquals($expected, $string); }
public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $t1->setIdentifierQuoting(true); $c1 = new Column(); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $t2->setIdentifierQuoting(true); $c2 = new Column(); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); return [[ColumnComparator::computeDiff($c1, $c2)]]; }
public function testValidateReturnsFalseWhenTwoColumnssHaveSamePhpName() { $column1 = new Column('foo'); $column2 = new Column('bar'); $column2->setPhpName('Foo'); $table = new Table('foo_table'); $table->addColumn($column1); $table->addColumn($column2); $appData = $this->getAppDataForTable($table); $validator = new SchemaValidator($appData); $this->assertFalse($validator->validate()); $this->assertContains('Column "bar" declares a phpName already used in table "foo_table"', $validator->getErrors()); }