Skip to content

Commit

Permalink
Fix connection uniqueness checks
Browse files Browse the repository at this point in the history
This logic has been wrong since skip options were added.

Refs #603
  • Loading branch information
markstory committed Mar 18, 2023
1 parent 7cdd082 commit e436e18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/TestSuite/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public function runMany(

$options[$i] = $migrationSet;
$connectionName = $migrationSet['connection'];
if (!in_array($connectionName, $connectionsList)) {
$connectionsList[] = ['name' => $connectionName, 'skip' => $skip];
if (!isset($connectionsList[$connectionName])) {
$connectionsList[$connectionName] = ['name' => $connectionName, 'skip' => $skip];
}

$migrations = new Migrations();
if (!in_array($connectionName, $connectionsToDrop) && $this->shouldDropTables($migrations, $migrationSet)) {
$connectionsToDrop[] = ['name' => $connectionName, 'skip' => $skip];
if (!isset($connectionsToDrop[$connectionName]) && $this->shouldDropTables($migrations, $migrationSet)) {
$connectionsToDrop[$connectionName] = ['name' => $connectionName, 'skip' => $skip];
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/TestSuite/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ public function testRunManyMultipleSkip(): void
$migrator->runMany([
['plugin' => 'Migrator'],
['plugin' => 'Migrator', 'source' => 'Migrations2'],
], false);
]);

// Run migrations the second time. Skip clauses will cause problems.
try {
$migrator->runMany([
['plugin' => 'Migrator', 'skip' => ['migrator']],
['plugin' => 'Migrator', 'source' => 'Migrations2', 'skip' => ['m*']],
], false);
]);
$this->fail('Should fail because of table drops');
} catch (RuntimeException $e) {
$connection->getDriver()->disconnect();
$this->assertStringContainsString('Could not apply migrations', $e->getMessage());
Expand Down

0 comments on commit e436e18

Please sign in to comment.