diff options
author | Lee Rowlands <lee.rowlands@previousnext.com.au> | 2023-12-28 08:03:14 +1000 |
---|---|---|
committer | Lee Rowlands <lee.rowlands@previousnext.com.au> | 2023-12-28 08:03:14 +1000 |
commit | fbee2baaab8fb8f8be29462e4798b51e1fe758d4 (patch) | |
tree | 976ab6bc1996f933d735884dfc83298074745fb4 /core/tests/Drupal/Tests/BrowserTestBase.php | |
parent | c980ece64ec31e8ae96a3c73d450472dff69b531 (diff) | |
download | drupal-fbee2baaab8fb8f8be29462e4798b51e1fe758d4.tar.gz drupal-fbee2baaab8fb8f8be29462e4798b51e1fe758d4.zip |
Issue #2484991 by znerol, voleger, andypost, dww, anmolgoyal74, markdorison, ankithashetty, larowlan, daffie, alexpott: Add the session to the request in KernelTestBase, BrowserTestBase, and drush
Diffstat (limited to 'core/tests/Drupal/Tests/BrowserTestBase.php')
-rw-r--r-- | core/tests/Drupal/Tests/BrowserTestBase.php | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 38b41f4163d..082292646ee 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -24,6 +24,7 @@ use Drupal\TestTools\TestVarDumper; use GuzzleHttp\Cookie\CookieJar; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; use Symfony\Component\VarDumper\VarDumper; /** @@ -446,6 +447,19 @@ abstract class BrowserTestBase extends TestCase { protected function tearDown(): void { parent::tearDown(); + if ($this->container) { + // Cleanup mock session started in DrupalKernel::preHandle(). + try { + /** @var \Symfony\Component\HttpFoundation\Session\Session $session */ + $session = $this->container->get('request_stack')->getSession(); + $session->clear(); + $session->save(); + } + catch (SessionNotFoundException) { + @trigger_error('Pushing requests without a session onto the request_stack is deprecated in drupal:10.3.0 and an error will be thrown from drupal:11.0.0. See https://www.drupal.org/node/3337193', E_USER_DEPRECATED); + } + } + // Destroy the testing kernel. if (isset($this->kernel)) { $this->cleanupEnvironment(); |