Skip to content

Commit

Permalink
make 2nd arg of Migrator::isIndexExists() optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 23, 2024
1 parent 0dac726 commit 703c0ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public function introspectTableToModel(string $tableName): Model
/**
* @param list<Field> $fields
*/
public function isIndexExists(array $fields, bool $requireUnique): bool
public function isIndexExists(array $fields, bool $requireUnique = false): bool
{
$fields = array_map(fn ($field) => $this->resolvePersistenceField($field), $fields);
$tableName = reset($fields)->getOwner()->table;
Expand Down
26 changes: 13 additions & 13 deletions tests/Schema/MigratorFkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testIsIndexExistsTableDoesNotExistException(): void

$this->expectException(Exception::class);
$this->expectExceptionMessage('Table does not exist');
$this->createMigrator()->isIndexExists([$client->getField('id')], false);
$this->createMigrator()->isIndexExists([$client->getField('id')]);
}

public function testCreateIndexNonUnique(): void
Expand All @@ -76,16 +76,16 @@ public function testCreateIndexNonUnique(): void

$this->createMigrator($client)->create();
self::assertSame([], $this->listTableIndexes('client'));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('id')], false));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('id')]));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('id')], true));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name')]));

$this->createMigrator()->createIndex([$client->getField('name')], false);
self::assertSame([[['name'], false]], $this->listTableIndexes('client'));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('name')], false));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('name')]));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name')], true));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('id'), $client->getField('name')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name'), $client->getField('id')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('id'), $client->getField('name')]));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name'), $client->getField('id')]));

$client->insert(['name' => 'Michael']);
$client->insert(['name' => 'Denise']);
Expand Down Expand Up @@ -113,10 +113,10 @@ public function testCreateIndexUnique(): void

$this->createMigrator()->createIndex([$client->getField('name')], true);
self::assertSame([[['name'], true]], $this->listTableIndexes('client'));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('name')], false));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('name')]));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('name')], true));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('id'), $client->getField('name')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name'), $client->getField('id')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('id'), $client->getField('name')]));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('name'), $client->getField('id')]));

$client->insert(['name' => 'Michael']);
$client->insert(['name' => 'Denise']);
Expand Down Expand Up @@ -155,12 +155,12 @@ public function testCreateIndexMultipleFields(): void

$this->createMigrator($client)->createIndex([$client->getField('a'), $client->getField('b')], true);
self::assertSame([[['a', 'b'], true]], $this->listTableIndexes('client'));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('a'), $client->getField('b')], false));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('a'), $client->getField('b')]));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('a'), $client->getField('b')], true));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('a')], false));
self::assertTrue($this->createMigrator()->isIndexExists([$client->getField('a')]));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('a')], true));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('b')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('b'), $client->getField('a')], false));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('b')]));
self::assertFalse($this->createMigrator()->isIndexExists([$client->getField('b'), $client->getField('a')]));
}

public function testForeignKeyViolation(): void
Expand Down

0 comments on commit 703c0ab

Please sign in to comment.