Skip to content

Commit

Permalink
Merge remote branch 'eriksencosta/DBAL-18'
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 13, 2010
2 parents 22c9f44 + 63f78cf commit ac91045
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 8 additions & 7 deletions lib/Doctrine/DBAL/Schema/SchemaDiff.php
@@ -1,7 +1,5 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand Down Expand Up @@ -82,9 +80,9 @@ class SchemaDiff
*
* @param array(string=>Table) $newTables
* @param array(string=>TableDiff) $changedTables
* @param array(string=>bool) $removedTables
* @param array(string=>bool) $removedTables
*/
public function __construct( $newTables = array(), $changedTables = array(), $removedTables = array() )
public function __construct($newTables = array(), $changedTables = array(), $removedTables = array())
{
$this->newTables = $newTables;
$this->changedTables = $changedTables;
Expand Down Expand Up @@ -155,8 +153,11 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false)
$sql,
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
);
foreach ($table->getForeignKeys() AS $foreignKey) {
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);

if ($platform->supportsForeignKeyConstraints()) {
foreach ($table->getForeignKeys() AS $foreignKey) {
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
}
}
}
$sql = array_merge($sql, $foreignKeySql);
Expand All @@ -173,4 +174,4 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false)

return $sql;
}
}
}
14 changes: 10 additions & 4 deletions tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php
Expand Up @@ -23,7 +23,7 @@ public function testSchemaDiffToSql()

$sql = $diff->toSql($platform);

$expected = array('drop_orphan_fk', 'drop_seq', 'create_seq', 'drop_seq', 'create_seq', 'create_table', 'drop_table', 'alter_table');
$expected = array('drop_orphan_fk', 'drop_seq', 'create_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table');

$this->assertEquals($expected, $sql);
}
Expand All @@ -35,7 +35,7 @@ public function testSchemaDiffToSaveSql()

$sql = $diff->toSaveSql($platform);

$expected = array('drop_seq', 'create_seq', 'create_seq', 'create_table', 'alter_table');
$expected = array('drop_seq', 'create_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table');

$this->assertEquals($expected, $sql);
}
Expand All @@ -61,6 +61,10 @@ public function createPlatform($dropSequenceCount=2, $dropTableCount=1, $dropOrp
->method('getCreateTableSql')
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
->will($this->returnValue(array('create_table')));
$platform->expects($this->exactly(1))
->method('getCreateForeignKeySQL')
->with($this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint'))
->will($this->returnValue('create_foreign_key'));
$platform->expects($this->exactly(1))
->method('getAlterTableSql')
->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff'))
Expand All @@ -74,7 +78,7 @@ public function createPlatform($dropSequenceCount=2, $dropTableCount=1, $dropOrp
$platform->expects($this->exactly(1))
->method('supportsSequences')
->will($this->returnValue(true));
$platform->expects($this->exactly(1))
$platform->expects($this->exactly(2))
->method('supportsForeignKeyConstraints')
->will($this->returnValue(true));
return $platform;
Expand All @@ -89,9 +93,11 @@ public function createSchemaDiff()
$diff->newTables['foo_table'] = new Table('foo_table');
$diff->removedTables['bar_table'] = new Table('bar_table');
$diff->changedTables['baz_table'] = new TableDiff('baz_table');
$diff->newTables['foo_table']->addColumn('foreign_id', 'integer');
$diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', array('foreign_id'), array('id'));
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id'), 'foreign_table', array('id'));
$fk->setLocalTable(new Table('local_table'));
$diff->orphanedForeignKeys[] = $fk;
return $diff;
}
}
}

0 comments on commit ac91045

Please sign in to comment.