Commit 2ebd2c90 authored by beberlei's avatar beberlei

[2.0] DDC-396 - Fixed bug with RESTRICT/NO ACTION and PHP NULL not valued as...

[2.0] DDC-396 - Fixed bug with RESTRICT/NO ACTION and PHP NULL not valued as the same in Schema Foreign Key Diff
parent 13ad5268
......@@ -280,19 +280,11 @@ class Comparator
return true;
}
if ($key1->hasOption('onUpdate') && $key->hasOption('onUpdate')) {
if ($key1->getOption('onUpdate') != $key2->getOption('onUpdate')) {
return true;
}
} else if ($key1->hasOption('onUpdate') != $key2->hasOption('onUpdate')) {
if ($key1->onUpdate() != $key2->onUpdate()) {
return true;
}
if ($key1->hasOption('onDelete') && $key2->hasOption('onDelete')) {
if ($key1->getOption('onDelete') != $key2->getOption('onDelete')) {
return true;
}
} else if ($key1->hasOption('onDelete') != $key2->hasOption('onDelete')) {
if ($key1->onDelete() != $key2->onDelete()) {
return true;
}
......
......@@ -126,4 +126,39 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
{
return $this->_options[$name];
}
}
\ No newline at end of file
/**
* Foreign Key onUpdate status
*
* @return string|null
*/
public function onUpdate()
{
return $this->_onEvent('onUpdate');
}
/**
* Foreign Key onDelete status
*
* @return string|null
*/
public function onDelete()
{
return $this->_onEvent('onDelete');
}
/**
* @param string $event
* @return string|null
*/
private function _onEvent($event)
{
if (isset($this->_options[$event])) {
$onEvent = strtoupper($this->_options[$event]);
if (!in_array($onEvent, array('NO ACTION', 'RESTRICT'))) {
return $onEvent;
}
}
return false;
}
}
......@@ -31,7 +31,8 @@ use Doctrine\DBAL\Schema\Schema,
Doctrine\DBAL\Schema\SchemaDiff,
Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Comparator,
Doctrine\DBAL\Types\Type;
Doctrine\DBAL\Types\Type,
Doctrine\DBAL\Schema\ForeignKeyConstraint;
/**
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......@@ -545,6 +546,15 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($tableDiff);
}
public function testCompareForeignKey_RestrictNoAction_AreTheSame()
{
$fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION'));
$fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT'));
$c = new Comparator();
$this->assertFalse($c->diffForeignKey($fk1, $fk2));
}
public function testDetectRenameColumn()
{
$tableA = new Table("foo");
......
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