protected function TestBase::rebuildContainer

Rebuild drupal_container().

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

3 calls to TestBase::rebuildContainer()
UpgradePathTestBase::performUpgrade in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
Perform the upgrade.
UpgradePathTestBase::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
WebTestBase::setUp in drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php, line 912
Definition of Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

protected function rebuildContainer() {

  // Create a new DrupalKernel for testing purposes, now that all required
  // modules have been enabled. This also stores a new dependency injection
  // container in drupal_container(). Drupal\simpletest\TestBase::tearDown()
  // restores the original container.
  // @see Drupal\Core\DrupalKernel::initializeContainer()
  $this->kernel = new DrupalKernel('testing', FALSE, drupal_classloader(), FALSE);

  // Booting the kernel is necessary to initialize the new DIC. While
  // normally the kernel gets booted on demand in
  // Symfony\Component\HttpKernel\handle(), this kernel needs manual booting
  // as it is not used to handle a request.
  $this->kernel
    ->boot();

  // The DrupalKernel does not update the container in drupal_container(), but
  // replaces it with a new object. We therefore need to replace the minimal
  // boostrap container that has been set up by TestBase::prepareEnvironment().
  $this->container = drupal_container();
}