diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 23524650c2..30ea156e42 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -618,17 +618,18 @@ public function discoverServiceProviders() { // Retrieve enabled modules and register their namespaces. if (!isset($this->moduleList)) { $extensions = $this->getConfigStorage()->read('core.extension'); - // If core.extension configuration does not exist then the container - // cannot be dumped because Drupal is yet to be installed. - if ($extensions === FALSE && $this->environment !== 'testing' && !InstallerKernel::installationAttempted()) { + // If core.extension configuration does not exist and we're not in the + // installer itself, then we need to put the kernel into a pre-installer + // mode. The container should not be dumped because Drupal is yet to be + // installed. The installer service provider is registered to ensure that + // cache and other automatically created tables are not created if + // database settings are available. None of this is required when the + // installer is running because the installer has its own kernel and + // manages the addition of its own service providers. + // @see \Drupal\KernelTests\KernelTestBase::bootKernel() + if ($extensions === FALSE && !InstallerKernel::installationAttempted()) { $this->allowDumping = FALSE; $this->containerNeedsDumping = FALSE; - // If we're not in the installer, register the installer service - // provider to ensure that cache tables are not created. This is - // required to correctly redirect to the installer without creating any - // incorrect caches. This is not required when the installer is running - // because the installer manages the addition of its own service - // providers. $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider'; } $this->moduleList = isset($extensions['module']) ? $extensions['module'] : []; diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 4539ed4850..032a5d62b8 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -341,10 +341,11 @@ private function bootKernel() { $kernel = new DrupalKernel('testing', $this->classLoader, FALSE); $kernel->setSitePath($this->siteDirectory); // Boot a new one-time container from scratch. Ensure to set the module list - // upfront to avoid a subsequent rebuild. - if ($modules && $extensions = $this->getExtensionsForModules($modules)) { - $kernel->updateModules($extensions, $extensions); - } + // upfront to avoid a subsequent rebuild or setting the kernel into the + // pre-installer mode. + $extensions = $modules ? $this->getExtensionsForModules($modules) : []; + $kernel->updateModules($extensions, $extensions); + // DrupalKernel::boot() is not sufficient as it does not invoke preHandle(), // which is required to initialize legacy global variables. $request = Request::create('/');