Commit 780add05 authored by catch's avatar catch

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 {
* 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;
}
......
......@@ -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);
}
/**
......
Markdown is supported
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