Unverified Commit de7b33d0 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Merge pull request #3519 from doctrine/fix-unique-constraint-with-empty-name

Fix UniqueConstraint with empty name.
parents acb9d148 f3ce0292
......@@ -865,7 +865,7 @@ class Table extends AbstractAsset
$name = strlen($constraint->getName())
? $constraint->getName()
: $this->_generateIdentifierName(
array_merge((array) $this->getName(), $constraint->getLocalColumns()),
array_merge((array) $this->getName(), $constraint->getColumns()),
'fk',
$this->_getMaxIdentifierLength()
);
......
......@@ -56,9 +56,6 @@ parameters:
# weird class name, represented in stubs as OCI_(Lob|Collection)
- '~unknown class OCI-(Lob|Collection)~'
# https://github.com/doctrine/dbal/issues/3236
- '~^Call to an undefined method Doctrine\\DBAL\\Schema\\UniqueConstraint::getLocalColumns\(\)~'
# https://github.com/doctrine/dbal/issues/3237
- '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOStatement::nextRowset\(\)~'
......
......@@ -12,9 +12,10 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use function array_shift;
use function array_keys;
use function current;
class TableTest extends DbalTestCase
......@@ -206,7 +207,11 @@ class TableTest extends DbalTestCase
$constraints = $tableA->getForeignKeys();
self::assertCount(1, $constraints);
self::assertSame($constraint, array_shift($constraints));
$constraintNames = array_keys($constraints);
self::assertSame('fk_8c736521', $constraintNames[0]);
self::assertSame($constraint, $constraints['fk_8c736521']);
}
public function testOptions() : void
......@@ -896,4 +901,33 @@ class TableTest extends DbalTestCase
$table->setComment('foo');
self::assertEquals('foo', $table->getComment());
}
public function testUniqueConstraintWithEmptyName() : void
{
$columns = [
new Column('column1', Type::getType(Type::STRING)),
new Column('column2', Type::getType(Type::STRING)),
new Column('column3', Type::getType(Type::STRING)),
new Column('column4', Type::getType(Type::STRING)),
];
$uniqueConstraints = [
new UniqueConstraint('', ['column1', 'column2']),
new UniqueConstraint('', ['column3', 'column4']),
];
$table = new Table('test', $columns, [], $uniqueConstraints);
$constraints = $table->getUniqueConstraints();
self::assertCount(2, $constraints);
$constraintNames = array_keys($constraints);
self::assertSame('fk_d87f7e0c341ce00bad15b1b1', $constraintNames[0]);
self::assertSame('fk_d87f7e0cda12812744761484', $constraintNames[1]);
self::assertSame($uniqueConstraints[0], $constraints['fk_d87f7e0c341ce00bad15b1b1']);
self::assertSame($uniqueConstraints[1], $constraints['fk_d87f7e0cda12812744761484']);
}
}
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