Commit ac910457 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge remote branch 'eriksencosta/DBAL-18'

parents 22c9f44b 63f78cf6
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -82,9 +80,9 @@ class SchemaDiff ...@@ -82,9 +80,9 @@ class SchemaDiff
* *
* @param array(string=>Table) $newTables * @param array(string=>Table) $newTables
* @param array(string=>TableDiff) $changedTables * @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->newTables = $newTables;
$this->changedTables = $changedTables; $this->changedTables = $changedTables;
...@@ -155,8 +153,11 @@ class SchemaDiff ...@@ -155,8 +153,11 @@ class SchemaDiff
$sql, $sql,
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES) $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); $sql = array_merge($sql, $foreignKeySql);
...@@ -173,4 +174,4 @@ class SchemaDiff ...@@ -173,4 +174,4 @@ class SchemaDiff
return $sql; return $sql;
} }
} }
\ No newline at end of file
...@@ -23,7 +23,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase ...@@ -23,7 +23,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase
$sql = $diff->toSql($platform); $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); $this->assertEquals($expected, $sql);
} }
...@@ -35,7 +35,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase ...@@ -35,7 +35,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase
$sql = $diff->toSaveSql($platform); $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); $this->assertEquals($expected, $sql);
} }
...@@ -61,6 +61,10 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase ...@@ -61,6 +61,10 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase
->method('getCreateTableSql') ->method('getCreateTableSql')
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table')) ->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
->will($this->returnValue(array('create_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)) $platform->expects($this->exactly(1))
->method('getAlterTableSql') ->method('getAlterTableSql')
->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff')) ->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff'))
...@@ -74,7 +78,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase ...@@ -74,7 +78,7 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase
$platform->expects($this->exactly(1)) $platform->expects($this->exactly(1))
->method('supportsSequences') ->method('supportsSequences')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$platform->expects($this->exactly(1)) $platform->expects($this->exactly(2))
->method('supportsForeignKeyConstraints') ->method('supportsForeignKeyConstraints')
->will($this->returnValue(true)); ->will($this->returnValue(true));
return $platform; return $platform;
...@@ -89,9 +93,11 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase ...@@ -89,9 +93,11 @@ class SchemaDiffTest extends \PHPUnit_Framework_TestCase
$diff->newTables['foo_table'] = new Table('foo_table'); $diff->newTables['foo_table'] = new Table('foo_table');
$diff->removedTables['bar_table'] = new Table('bar_table'); $diff->removedTables['bar_table'] = new Table('bar_table');
$diff->changedTables['baz_table'] = new TableDiff('baz_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 = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id'), 'foreign_table', array('id'));
$fk->setLocalTable(new Table('local_table')); $fk->setLocalTable(new Table('local_table'));
$diff->orphanedForeignKeys[] = $fk; $diff->orphanedForeignKeys[] = $fk;
return $diff; return $diff;
} }
} }
\ No newline at end of file
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