Commit 2cb22496 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix bug in Index::overrules()

parent 4cfb32db
...@@ -76,6 +76,16 @@ class Index extends AbstractAsset implements Constraint ...@@ -76,6 +76,16 @@ class Index extends AbstractAsset implements Constraint
{ {
return $this->_columns; return $this->_columns;
} }
/**
* Is the index neither unique nor primary key?
*
* @return bool
*/
public function isSimpleIndex()
{
return !$this->_isPrimary && !$this->_isUnique;
}
/** /**
* @return bool * @return bool
...@@ -164,7 +174,9 @@ class Index extends AbstractAsset implements Constraint ...@@ -164,7 +174,9 @@ class Index extends AbstractAsset implements Constraint
*/ */
public function overrules(Index $other) public function overrules(Index $other)
{ {
if ($other->isPrimary() || $other->isUnique()) { if ($other->isPrimary()) {
return false;
} else if ($this->isSimpleIndex() && $other->isUnique()) {
return false; return false;
} }
......
...@@ -406,6 +406,21 @@ class TableTest extends \PHPUnit_Framework_TestCase ...@@ -406,6 +406,21 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1, count($table->getIndexes())); $this->assertEquals(1, count($table->getIndexes()));
$this->assertFalse($table->hasIndex($index->getName())); $this->assertFalse($table->hasIndex($index->getName()));
} }
public function testPrimaryKeyOverrulesUniqueIndex()
{
$table = new Table("bar");
$table->addColumn('baz', 'integer', array());
$table->addUniqueIndex(array('baz'));
$table->setPrimaryKey(array('baz'));
$indexes = $table->getIndexes();
$this->assertEquals(1, count($indexes), "Table should only contain the primary key table index, not the unique one anymore, because it was overruled.");
$index = current($indexes);
$this->assertTrue($index->isPrimary());
}
/** /**
* @group DBAL-64 * @group DBAL-64
......
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