Commit 780add05 authored by catch's avatar catch
Browse files

Issue #2171315 by sun, Xano, diarmy, tim.plunkett: Ensure a NULL container in...

Issue #2171315 by sun, Xano, diarmy, tim.plunkett: Ensure a NULL container in UnitTestCase::setUp().
parent 8bab6674
...@@ -102,9 +102,11 @@ class Drupal { ...@@ -102,9 +102,11 @@ class Drupal {
* Sets a new global container. * Sets a new global container.
* *
* @param \Symfony\Component\DependencyInjection\ContainerInterface $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; static::$container = $container;
} }
......
...@@ -48,12 +48,11 @@ public static function getInfo() { ...@@ -48,12 +48,11 @@ public static function getInfo() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function tearDown() { protected function setUp() {
parent::tearDown(); parent::setUp();
if (\Drupal::getContainer()) { // Ensure that an instantiated container in the global state of \Drupal from
$container = new ContainerBuilder(); // a previous test does not leak into this test.
\Drupal::setContainer($container); \Drupal::setContainer(NULL);
}
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment