Commit 7a150d14 authored by webchick's avatar webchick

Issue #2014015 by kgoel, dmitrii, Berdir: Replace drupal_container() with...

Issue #2014015 by kgoel, dmitrii, Berdir: Replace drupal_container() with Drupal::service() in the simpletest module.
parent 662bd393
...@@ -88,7 +88,7 @@ protected function setUp() { ...@@ -88,7 +88,7 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Build a minimal, partially mocked environment for unit tests. // Build a minimal, partially mocked environment for unit tests.
$this->containerBuild(drupal_container()); $this->containerBuild(\Drupal::getContainer());
// Make sure it survives kernel rebuilds. // Make sure it survives kernel rebuilds.
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider'; $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
...@@ -156,7 +156,7 @@ public function containerBuild(ContainerBuilder $container) { ...@@ -156,7 +156,7 @@ public function containerBuild(ContainerBuilder $container) {
$container->set('keyvalue.memory', $this->keyValueFactory); $container->set('keyvalue.memory', $this->keyValueFactory);
if (!$container->has('keyvalue')) { if (!$container->has('keyvalue')) {
// TestBase::setUp puts a completely empty container in // TestBase::setUp puts a completely empty container in
// drupal_container() which is somewhat the mirror of the empty // $this->container which is somewhat the mirror of the empty
// environment being set up. Unit tests need not to waste time with // environment being set up. Unit tests need not to waste time with
// getting a container set up for them. Drupal Unit Tests might just get // getting a container set up for them. Drupal Unit Tests might just get
// away with a simple container holding the absolute bare minimum. When // away with a simple container holding the absolute bare minimum. When
......
...@@ -912,7 +912,7 @@ protected function prepareEnvironment() { ...@@ -912,7 +912,7 @@ protected function prepareEnvironment() {
$this->originalConf = $conf; $this->originalConf = $conf;
// Backup statics and globals. // Backup statics and globals.
$this->originalContainer = clone drupal_container(); $this->originalContainer = clone \Drupal::getContainer();
$this->originalLanguage = $language_interface; $this->originalLanguage = $language_interface;
$this->originalConfigDirectories = $GLOBALS['config_directories']; $this->originalConfigDirectories = $GLOBALS['config_directories'];
if (isset($GLOBALS['theme_key'])) { if (isset($GLOBALS['theme_key'])) {
...@@ -1065,6 +1065,15 @@ protected function tearDown() { ...@@ -1065,6 +1065,15 @@ protected function tearDown() {
// which means they may need to access its filesystem and database. // which means they may need to access its filesystem and database.
drupal_static_reset(); drupal_static_reset();
if ($this->container->has('state') && $state = $this->container->get('state')) {
$captured_emails = $state->get('system.test_email_collector') ?: array();
$emailCount = count($captured_emails);
if ($emailCount) {
$message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
$this->pass($message, t('E-mail'));
}
}
// Ensure that TestBase::changeDatabasePrefix() has run and TestBase::$setup // Ensure that TestBase::changeDatabasePrefix() has run and TestBase::$setup
// was not tricked into TRUE, since the following code would delete the // was not tricked into TRUE, since the following code would delete the
// entire parent site otherwise. // entire parent site otherwise.
...@@ -1086,14 +1095,6 @@ protected function tearDown() { ...@@ -1086,14 +1095,6 @@ protected function tearDown() {
// In case a fatal error occurred that was not in the test process read the // In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors. // log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE); simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
if (($container = drupal_container()) && $container->has('keyvalue')) {
$captured_emails = \Drupal::state()->get('system.test_email_collector') ?: array();
$emailCount = count($captured_emails);
if ($emailCount) {
$message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
$this->pass($message, t('E-mail'));
}
}
// Delete temporary files directory. // Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10), array($this, 'filePreDeleteCallback')); file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10), array($this, 'filePreDeleteCallback'));
......
...@@ -1007,7 +1007,7 @@ protected function refreshVariables() { ...@@ -1007,7 +1007,7 @@ protected function refreshVariables() {
$conf = variable_initialize(); $conf = variable_initialize();
// Clear the tag cache. // Clear the tag cache.
drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache'); drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache');
drupal_container()->get('config.factory')->reset(); \Drupal::service('config.factory')->reset();
} }
/** /**
......
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