diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0d72a1b..9e457ce 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1221,6 +1221,11 @@ function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) * \Drupal::service('messenger')->getMessagesByType() instead. */ function drupal_get_messages($type = NULL, $clear_queue = TRUE) { + // Workaround for Drush. + if (!\Drupal::hasService('messenger')) { + return array(); + } + /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */ $messenger = \Drupal::service('messenger'); diff --git a/core/tests/Drupal/Tests/Core/Messenger/MessengerTest.php b/core/tests/Drupal/Tests/Core/Messenger/MessengerTest.php index af4b6cf..1a042bc 100644 --- a/core/tests/Drupal/Tests/Core/Messenger/MessengerTest.php +++ b/core/tests/Drupal/Tests/Core/Messenger/MessengerTest.php @@ -46,7 +46,7 @@ public static function getInfo() { public function setUp() { $this->messenger = new Messenger(); - $this->existingSession = isset($_SESSION) ? $_SESSION : array(); + $this->existingSession = isset($_SESSION) ? $_SESSION : NULL; $_SESSION = array(); } @@ -54,9 +54,12 @@ public function setUp() { * {@inheritdoc} */ public function tearDown() { - if (!empty($this->existingSession)) { + if ($this->existingSession !== NULL) { $_SESSION = $this->existingSession; } + else { + unset($_SESSION); + } } /**