function FunctionalTestSetupTrait::rebuildContainer

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer()
  2. 8.9.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer()
  3. 10 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()

94 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.
BlockInstallTest::testCacheTagInvalidationUponInstallation in core/modules/block/tests/src/Functional/BlockInstallTest.php
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.
CommentAdminTest::testCommentedTranslationDeletion in core/modules/comment/tests/src/Functional/CommentAdminTest.php
Tests commented translation deletion admin view.

... See full list

File

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

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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.