Skip to content

Commit

Permalink
Merge pull request #4667 from hschletz/fix-removeUniqueConstraint-wro…
Browse files Browse the repository at this point in the history
…ng-method

Make Table::removeUniqueConstraint() actually work
  • Loading branch information
greg0ire committed Jun 6, 2021
2 parents b5c2979 + 0e398ec commit 7ef2a33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Schema/Table.php
Expand Up @@ -686,7 +686,7 @@ public function removeUniqueConstraint(string $name): void
{
$name = $this->normalizeIdentifier($name);

if (! $this->hasForeignKey($name)) {
if (! $this->hasUniqueConstraint($name)) {
throw SchemaException::uniqueConstraintDoesNotExist($name, $this->_name);
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Schema/TableTest.php
Expand Up @@ -831,4 +831,25 @@ public function testTableComment(): void
$table->setComment('foo');
self::assertEquals('foo', $table->getComment());
}

public function testRemoveUniqueConstraint(): void
{
$table = new Table('foo');
$table->addColumn('bar', 'integer');
$table->addUniqueConstraint(['bar'], 'unique_constraint');

$table->removeUniqueConstraint('unique_constraint');

self::assertFalse($table->hasUniqueConstraint('unique_constraint'));
}

public function testRemoveUniqueConstraintUnknownNameThrowsException(): void
{
$this->expectException(SchemaException::class);

$table = new Table('foo');
$table->addColumn('bar', 'integer');

$table->removeUniqueConstraint('unique_constraint');
}
}

0 comments on commit 7ef2a33

Please sign in to comment.