Skip to content

Commit 2c7e6d6

Browse files
committed
fix(Session): clear session data on destroy in testing environment
1 parent 19cae6e commit 2c7e6d6

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

system/Session/Session.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ private function removeOldSessionCookie(): void
274274
public function destroy()
275275
{
276276
if (ENVIRONMENT === 'testing') {
277+
$_SESSION = [];
278+
277279
return;
278280
}
279281

tests/system/Session/SessionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ public function testSetMagicMethod(): void
328328
$this->assertSame('bar', $_SESSION['foo']);
329329
}
330330

331+
public function testDestroyClearsSessionInTesting(): void
332+
{
333+
$session = $this->getInstance();
334+
$session->start();
335+
336+
$session->set('foo', 'bar');
337+
$this->assertSame('bar', $_SESSION['foo']);
338+
339+
$session->destroy();
340+
341+
$this->assertSame([], $_SESSION);
342+
}
343+
331344
public function testCanFlashData(): void
332345
{
333346
$session = $this->getInstance();

0 commit comments

Comments
 (0)