diff --git a/system/Session/Session.php b/system/Session/Session.php index 1c3824928775..f1901377d0d5 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -274,6 +274,8 @@ private function removeOldSessionCookie(): void public function destroy() { if (ENVIRONMENT === 'testing') { + $_SESSION = []; + return; } diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 3b7cd3860ccd..e66b3f868f97 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -328,6 +328,19 @@ public function testSetMagicMethod(): void $this->assertSame('bar', $_SESSION['foo']); } + public function testDestroyClearsSessionInTesting(): void + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + $this->assertSame('bar', $_SESSION['foo']); + + $session->destroy(); + + $this->assertSame([], $_SESSION); + } + public function testCanFlashData(): void { $session = $this->getInstance();