You are here

protected function FunctionalTestSetupTrait::rebuildContainer in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer()
  2. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer()

Rebuilds \Drupal::getContainer().

Use this to update the test process's kernel with a new service container. For example, when the list of enabled modules is changed via the internal browser the test process's kernel has a service container with an out of date module list.

@todo Fix https://www.drupal.org/node/2941757 so that module enable/disable changes are immediately reflected in \Drupal::getContainer(). Until then, tests can invoke this workaround when requiring services from newly enabled modules to be immediately available in the same request.

See also

TestBase::prepareEnvironment()

TestBase::restoreEnvironment()

23 calls to FunctionalTestSetupTrait::rebuildContainer()
ActiveWorkspaceUpdateTest::setUp in core/modules/workspaces/tests/src/Functional/UpdateSystem/ActiveWorkspaceUpdateTest.php
AjaxFormCacheTest::testBlockForms in core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
Tests AJAX forms in blocks.
ClassLoaderTest::testMultipleModules in core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
Ensures the negative caches in the class loader don't result in crashes.
ConfigTest::testFileConfigurationPage in core/modules/system/tests/src/Functional/File/ConfigTest.php
Tests file configuration page.
CorsIntegrationTest::testCrossSiteRequest in core/tests/Drupal/FunctionalTests/HttpKernel/CorsIntegrationTest.php

... See full list

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 206

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function rebuildContainer() {

  // Rebuild the kernel and bring it back to a fully bootstrapped state.
  $this->container = $this->kernel
    ->rebuildContainer();

  // Make sure the url generator has a request object, otherwise calls to
  // $this->drupalGet() will fail.
  $this
    ->prepareRequestForGenerator();
}