diff --git a/src/Migration/ManagerFactory.php b/src/Migration/ManagerFactory.php index 09ea5dfe..a86c1a2a 100644 --- a/src/Migration/ManagerFactory.php +++ b/src/Migration/ManagerFactory.php @@ -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 $connectionConfig */ $adapter = $connectionConfig['scheme'] ?? null; diff --git a/tests/TestCase/Command/MigrateCommandTest.php b/tests/TestCase/Command/MigrateCommandTest.php index 497839f0..1950d11c 100644 --- a/tests/TestCase/Command/MigrateCommandTest.php +++ b/tests/TestCase/Command/MigrateCommandTest.php @@ -42,6 +42,7 @@ public function tearDown(): void foreach ($this->createdFiles as $file) { unlink($file); } + ConnectionManager::drop('invalid'); } public function testHelp() @@ -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 */