diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 7569746..9efc0a1 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -125,15 +125,9 @@ class Drupal { * Sets a new global container. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * 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. + * A new container instance to replace the current. */ - public static function setContainer(ContainerInterface $container = NULL) { - if (!isset($container)) { - // @todo Remove the NULL case, and use unsetContainer() instead. - $container = new PlaceholderContainer('\Drupal::$container was unset with setContainer(NULL).'); - } + public static function setContainer(ContainerInterface $container) { static::$container = $container; } diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index b4901af..a6d1bf2 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1187,7 +1187,7 @@ private function prepareEnvironment() { // Ensure there is no service container. $this->container = NULL; - \Drupal::setContainer(NULL); + \Drupal::unsetContainer(); // Unset globals. unset($GLOBALS['config_directories']); diff --git a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php index a7bcca7..1636b1f 100644 --- a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php +++ b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php @@ -16,10 +16,32 @@ */ class GetFilenameUnitTest extends KernelTestBase { + /** + * The container used by the test, moved out of the way. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $previousContainer; + + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); + // Store the previous container. + $this->previousContainer = $this->container; $this->container = NULL; - \Drupal::setContainer(NULL); + \Drupal::unsetContainer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() { + parent::tearDown(); + // Restore the previous container. + $this->container = $this->previousContainer; + \Drupal::setContainer($this->previousContainer); } /** diff --git a/core/modules/system/src/Tests/Routing/RouteProviderTest.php b/core/modules/system/src/Tests/Routing/RouteProviderTest.php index be8862c..6ba9f97 100644 --- a/core/modules/system/src/Tests/Routing/RouteProviderTest.php +++ b/core/modules/system/src/Tests/Routing/RouteProviderTest.php @@ -50,6 +50,7 @@ class RouteProviderTest extends KernelTestBase { protected $state; protected function setUp() { + parent::setUp(); $this->fixtures = new RoutingFixtures(); $this->routeBuilder = new NullRouteBuilder(); $this->state = new State(new KeyValueMemoryFactory()); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index d6deb9e..e82c3a9 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -39,7 +39,7 @@ 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); + \Drupal::unsetContainer(); $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); }