diff -u b/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php --- b/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -2,5 +2,6 @@ namespace Drupal\Core\Database; + use GuzzleHttp\Psr7\Uri; /** @@ -1437,8 +1438,6 @@ /** * A helper function to convert a URI into connection options. * - * This method can be overridden in order to customise how a URI is converted. - * * @internal * This method should not be called. Use * \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo() instead. @@ -1470,9 +1469,6 @@ /** * A helper function to convert connection options into a URI. * - * This method can be overridden in order to customise how connection options - * are converted. - * * @internal * This method should not be called. Use * \Drupal\Core\Database\Database::getConnectionInfoAsUrl() instead. @@ -1488,14 +1484,8 @@ * @see \Drupal\Core\Database\Database::getConnectionInfoAsUrl() */ public static function getConnectionInfoAsUrlHelper(array $connection_options, Uri $uri) { - $user = ''; - if ($connection_options['username']) { - $user = $connection_options['username']; - } - $password = ''; - if ($connection_options['password']) { - $password = $connection_options['password']; - } + $user = isset($connection_options['username']) ? $connection_options['username'] : ''; + $password = isset($connection_options['password']) ? $connection_options['password'] : ''; $uri = $uri->withUserInfo($user, $password); if (!empty($connection_options['port'])) { $uri = $uri->withPort($connection_options['port']); diff -u b/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php --- b/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -453,7 +453,7 @@ */ public static function convertDbUrlToConnectionInfo($url, $root) { $uri = new Uri($url); - if (empty($uri->getHost()) || empty($uri->getHost()) || empty($uri->getPath())) { + if (empty($uri->getHost()) || empty($uri->getSchema()) || empty($uri->getPath())) { throw new \InvalidArgumentException('Minimum requirement: driver://host/database'); } diff -u b/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module --- b/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -262,11 +262,9 @@ * The results as returned by exec(). */ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) { - 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()); - } + // 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( @@ -307,9 +305,11 @@ */ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) { global $base_url; - // 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()); + } // Setup an environment variable containing the base URL, if it is available. // This allows functional tests to browse the site under test. When running @@ -333,7 +333,7 @@ } else { // Double escape namespaces so they'll work in a regexp. - $escaped_test_classnames = array_map(function($class) { + $escaped_test_classnames = array_map(function ($class) { return addslashes($class); }, $unescaped_test_classnames); diff -u b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php --- b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConnectionTest.php @@ -173,7 +173,7 @@ */ public function testGetDriverClass($expected, $namespace, $class) { $mock_pdo = $this->getMock('Drupal\Tests\Core\Database\Stub\StubPDO'); - $connection = new StubConnection($mock_pdo, array('namespace' => $namespace)); + $connection = new Connection($mock_pdo, array('namespace' => $namespace)); // Set the driver using our stub class' public property. $this->assertEquals($expected, $connection->getDriverClass($class)); } @@ -181,7 +181,7 @@ */ public function testGetDriverClass($expected, $driver, $namespace, $class) { $mock_pdo = $this->getMock('Drupal\Tests\Core\Database\Stub\StubPDO'); - $connection = new Connection($mock_pdo, array('namespace' => $namespace)); + $connection = new StubConnection($mock_pdo, array('namespace' => $namespace)); // Set the driver using our stub class' public property. $connection->driver = $driver; $this->assertEquals($expected, $connection->getDriverClass($class)); diff -u b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php --- b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php +++ b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php @@ -1,10 +1,5 @@ setExpectedException(\RuntimeException::class, 'Database connection default not defined'); Database::getConnectionInfoAsUrl(); @@ -46,7 +44,6 @@ $this->assertSame($expected, $connection_options); } - /** * Data provider for self::testconvertDbUrlToConnectionInfo(). */ @@ -176 +173 @@ -} \ No newline at end of file +} interdiff impossible; taking evasive action reverted: --- b/core/tests/Drupal/Tests/Core/Database/Stub/Connection.php +++ a/core/tests/Drupal/Tests/Core/Database/Stub/StubConnection.php @@ -2,12 +2,12 @@ /** * @file + * Contains \Drupal\Tests\Core\Database\Stub\StubConnection. - * Contains \Drupal\Tests\Core\Database\Stub\Connection. */ namespace Drupal\Tests\Core\Database\Stub; +use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Connection as DatabaseConnection; use Drupal\Core\Database\StatementEmpty; /** @@ -15,7 +15,7 @@ * * Includes minimal implementations of Connection's abstract methods. */ +class StubConnection extends Connection { -class Connection extends DatabaseConnection { /** * Public property so we can test driver loading mechanism. unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Database/Stub/Connection.php @@ -0,0 +1,77 @@ +driver; + } + + /** + * {@inheritdoc} + */ + public function databaseType() { + return 'stub'; + } + + /** + * {@inheritdoc} + */ + public function createDatabase($database) { + return; + } + + /** + * {@inheritdoc} + */ + public function mapConditionOperator($operator) { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function nextId($existing_id = 0) { + return 0; + } + +} only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Core/Database/Stub/StubConnection.php +++ /dev/null @@ -1,72 +0,0 @@ -driver; - } - - /** - * {@inheritdoc} - */ - public function databaseType() { - return 'stub'; - } - - /** - * {@inheritdoc} - */ - public function createDatabase($database) { - return; - } - - /** - * {@inheritdoc} - */ - public function mapConditionOperator($operator) { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function nextId($existing_id = 0) { - return 0; - } - -}