Commit 68558492 authored by Steve Müller's avatar Steve Müller

Merge pull request #867 from zeroedin-bill/fix-fk-schemadiff-renamed-column

Add test for schemadiff on table with renamed fk column referencing renamed table
parents a7921203 bdb2f2de
......@@ -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