diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index b611cdc..0e2fab2 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -503,11 +503,13 @@ public static function getConnectionInfoAsUrl($key = 'default') { $namespace = isset($db_info['default']['namespace']) ? $db_info['default']['namespace'] : NULL; $driver_class = static::getDatabaseConnectionClass($db_info['default']['driver'], $namespace); - $uri = new Uri(NULL); - $uri = $uri - ->withScheme($db_info['default']['driver']) - ->withHost($db_info['default']['host']) - ->withPath($db_info['default']['database']); + + // Some database driver do not need a host setting to work but in order to + // be converted into a URL they do. + $host = isset($db_info['default']['host']) ? $db_info['default']['host'] : 'localhost'; + + // Create a URI with the minimum requirement of driver://host/database. + $uri = new Uri($db_info['default']['driver'] . '://' . $host . '/' . $db_info['default']['database']); if (!empty($db_info['default']['prefix']['default'])) { $uri = $uri->withFragment($db_info['default']['prefix']['default']); diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index daaf828..1896dd7 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -425,6 +425,8 @@ public static function convertDbUrlToConnectionInfoHelper(Uri $uri, $root, array if ($database['database'][0] !== '/') { $database['database'] = $root . '/' . $database['database']; } + // The host setting is meaningless for SQLite databases. + unset($database['host']); return $database; } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 4dc7544..d589466 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -262,9 +262,11 @@ function simpletest_phpunit_configuration_filepath() { * The results as returned by exec(). */ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) { - // Setup an environment variable containing the database connection so that - // functional tests can connect to the database. - putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl()); + if (Database::getConnectionInfo()) { + // Setup an environment variable containing the database connection so that + // functional tests can connect to the database. + putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl()); + } $phpunit_bin = simpletest_phpunit_command(); $command = array( diff --git a/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php index 6046ab5..7c17d06 100644 --- a/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php +++ b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php @@ -56,7 +56,6 @@ public function providerTestconvertDbUrlToConnectionInfo() { 'sqlite://localhost/database_file', [ 'driver' => 'sqlite', - 'host' => 'localhost', 'database' => '/root/database_file', 'prefix' => NULL, 'namespace' => '', @@ -88,7 +87,6 @@ public function providerGetConnectionInfoAsUrl() { 'sqlite://localhost/database_file', [ 'driver' => 'sqlite', - 'host' => 'localhost', 'database' => 'database_file', 'prefix' => NULL, 'namespace' => '', @@ -143,7 +141,6 @@ protected function baseConnectionConvertProviderData() { 'sqlite://localhost//absolute/database_file', [ 'driver' => 'sqlite', - 'host' => 'localhost', 'database' => '/absolute/database_file', 'prefix' => NULL, 'namespace' => '',