diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 1ea2bc1..e1507d5 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -102,9 +102,11 @@ class Drupal { * Sets a new global container. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * A new container instance to replace the current. + * A new container instance to replace the current. NULL may be passed by + * testing frameworks to ensure that the global state of a previous + * environment does not leak into a test. */ - public static function setContainer(ContainerInterface $container) { + public static function setContainer(ContainerInterface $container = NULL) { static::$container = $container; } diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index ca0968d..b862f12 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -48,12 +48,11 @@ public static function getInfo() { /** * {@inheritdoc} */ - protected function tearDown() { - parent::tearDown(); - if (\Drupal::getContainer()) { - $container = new ContainerBuilder(); - \Drupal::setContainer($container); - } + protected function setUp() { + parent::setUp(); + // Ensure that an instantiated container in the global state of \Drupal from + // a previous test does not leak into this test. + \Drupal::setContainer(NULL); } /**