Skip to content

Commit

Permalink
Merge pull request #758 from cakephp/fix-notice-error
Browse files Browse the repository at this point in the history
Fix notice error in ManagerFactory for invalid connections
  • Loading branch information
dereuromark authored Oct 19, 2024
2 parents 40b5ef9 + 69dde8c commit 3518c48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Migration/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function createConfig(): ConfigInterface
if (!$connectionConfig) {
throw new RuntimeException("Could not find connection `{$connectionName}`");
}
if (!isset($connectionConfig['database'])) {
throw new RuntimeException("The `{$connectionName}` connection has no `database` key defined.");
}

/** @var array<string, string> $connectionConfig */
$adapter = $connectionConfig['scheme'] ?? null;
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/Command/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function tearDown(): void
foreach ($this->createdFiles as $file) {
unlink($file);
}
ConnectionManager::drop('invalid');
}

public function testHelp()
Expand Down Expand Up @@ -72,6 +73,18 @@ public function testMigrateNoMigrationSource(): void
$this->assertFileDoesNotExist($dumpFile);
}

/**
* Test that source parameter defaults to Migrations
*/
public function testMigrateInvalidConnection(): void
{
ConnectionManager::setConfig('invalid', [
'database' => null,
]);
$this->expectExceptionMessage('has no `database` key defined');
$this->exec('migrations migrate -c invalid');
}

/**
* Test that source parameter defaults to Migrations
*/
Expand Down

0 comments on commit 3518c48

Please sign in to comment.