diff -u b/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php --- b/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -1061,10 +1061,9 @@ $this->prepareDatabasePrefix(); } - // Clone the current connection and replace the current prefix. - $connection_info = Database::getConnectionInfo('default'); - if (is_null($connection_info)) { - $db_url = getenv('SIMPLETEST_DB'); + // If the test is run with argument dburl then use it. + $db_url = defined('SIMPLETEST_DB') ? getenv('SIMPLETEST_DB') : ''; + if (!empty($db_url)) { $info = parse_url($db_url); if (!isset($info['scheme'], $info['host'], $info['path'])) { throw new \InvalidArgumentException('Invalid --dburl. Minimum requirement: driver://host/database.'); @@ -1095,6 +1094,12 @@ } Database::addConnectionInfo('default', 'default', $database); } + + // Clone the current connection and replace the current prefix. + $connection_info = Database::getConnectionInfo('default'); + if (is_null($connection_info)) { + throw new \InvalidArgumentException('There is no database connection so no tests can be run.'); + } else { Database::renameConnection('default', 'simpletest_original_default'); foreach ($connection_info as $target => $value) {