Commit bdb2f2de authored by Bill Schaller's avatar Bill Schaller

Add test to ensure renamed or removed columns that reference removed tables...

Add test to ensure renamed or removed columns that reference removed tables have their FK constraints properly removed.
parent a3a86aa5
......@@ -1232,4 +1232,44 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
array('0', 'foo', false),
);
}
public function testForeignKeyRemovalWithRenamedLocalColumn()
{
$fromSchema = new Schema( array(
'table1' => new Table('table1',
array(
'id' => new Column('id', Type::getType('integer')),
)),
'table2' => new Table('table2',
array(
'id' => new Column('id', Type::getType('integer')),
'id_table1' => new Column('id_table1', Type::getType('integer'))
),
array(),
array(
new ForeignKeyConstraint(array('id_table1'), 'table1', array('id'), 'fk_table2_table1')
))
));
$toSchema = new Schema( array(
'table2' => new Table('table2',
array(
'id' => new Column('id', Type::getType('integer')),
'id_table3' => new Column('id_table3', Type::getType('integer'))
),
array(),
array(
new ForeignKeyConstraint(array('id_table3'), 'table3', array('id'), 'fk_table2_table3')
)),
'table3' => new Table('table3',
array(
'id' => new Column('id', Type::getType('integer'))
))
));
$actual = Comparator::compareSchemas($fromSchema, $toSchema);
$this->assertArrayHasKey("table2", $actual->changedTables);
$this->assertCount(1, $actual->orphanedForeignKeys);
$this->assertEquals("fk_table2_table1", $actual->orphanedForeignKeys[0]->getName());
$this->assertCount(1, $actual->changedTables['table2']->addedForeignKeys, "FK to table3 should be added.");
$this->assertEquals("table3", $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment