only in patch2: unchanged: --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -336,6 +336,20 @@ private function bootKernel() { $modules = self::getModulesToEnable(static::class); + // When a module is providing the database driver, then enable that module. + $connection_info = Database::getConnectionInfo(); + $driver = $connection_info['default']['driver']; + $namespace = $connection_info['default']['namespace'] ?? NULL; + $autoload = $connection_info['default']['autoload'] ?? NULL; + if (strpos($autoload, 'src/Driver/Database/') !== FALSE) { + [$first, $second] = explode('\\', $namespace, 3); + if ($first === 'Drupal' && strtolower($second) === $second) { + // Add the module that provides the database driver to the list of + // modules as the first to be enabled. + array_unshift($modules, $second); + } + } + // Bootstrap the kernel. Do not use createFromRequest() to retain Settings. $kernel = new DrupalKernel('testing', $this->classLoader, FALSE); $kernel->setSitePath($this->siteDirectory); @@ -357,9 +371,6 @@ private function bootKernel() { // Ensure database tasks have been run. require_once __DIR__ . '/../../../includes/install.inc'; - $connection_info = Database::getConnectionInfo(); - $driver = $connection_info['default']['driver']; - $namespace = $connection_info['default']['namespace'] ?? NULL; $errors = db_installer_object($driver, $namespace)->runTasks(); if (!empty($errors)) { $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors)); only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/KernelTests/KernelTestBaseDatabaseDriverModuleTest.php @@ -0,0 +1,66 @@ +root); + + // Change the used database driver to the one provided by the module + // "driver_test". + $driver = 'Drivertest' . ucfirst($database['driver']); + $database['driver'] = $driver; + $database['namespace'] = 'Drupal\\driver_test\\Driver\\Database\\' . $driver; + $database['autoload'] = "core/modules/system/tests/modules/driver_test/src/Driver/Database/$driver/"; + + Database::addConnectionInfo('default', 'default', $database); + } + + // Clone the current connection and replace the current prefix. + $connection_info = Database::getConnectionInfo('default'); + if (!empty($connection_info)) { + Database::renameConnection('default', 'simpletest_original_default'); + foreach ($connection_info as $target => $value) { + // Replace the full table prefix definition to ensure that no table + // prefixes of the test runner leak into the test. + $connection_info[$target]['prefix'] = [ + 'default' => $this->databasePrefix, + ]; + } + } + return $connection_info; + } + + /** + * @covers ::bootEnvironment + */ + public function testDatabaseDriverModuleEnabled() { + $driver = Database::getConnection()->driver(); + if (!in_array($driver, ['DrivertestMysql', 'DrivertestPgsql'])) { + $this->markTestSkipped("This test does not support the {$driver} database driver."); + } + + // Test that the module that is providing the database driver is enabled. + $this->assertSame(1, \Drupal::service('extension.list.module')->get('driver_test')->status); + } + +}