Skip to content

Commit

Permalink
fix $_SESSION data loss on multiple subsequent `DummySession::open(…
Browse files Browse the repository at this point in the history
…)` invocations
  • Loading branch information
klimov-paul committed Jun 14, 2023
1 parent d53574c commit 7cedc8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Yii1 Dummy Session extension
============================

1.0.1 Under Development
-----------------------

- Bug: Fixed `$_SESSION` data loss on multiple subsequent `DummySession::open()` invocations (klimov-paul)


1.0.0, June 13, 2023
--------------------

Expand Down
6 changes: 4 additions & 2 deletions src/DummySession.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public function init(): void
*/
public function open()
{
$this->_id = uniqid();
$_SESSION = [];
if ($this->_id === null) {
$this->_id = uniqid();
$_SESSION = [];
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/DummySessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public function testOpenSession(): void
$this->assertNotEmpty($session->getSessionID());
}

/**
* @depends testOpenSession
*/
public function testMultipleOpenSession(): void
{
$session = new DummySession();

$session->open();

$_SESSION['foo'] = 'bar';
$sessionId = $session->getSessionID();

$session->open();

$this->assertNotEmpty($_SESSION);
$this->assertEquals($sessionId, $session->getSessionID());
}

/**
* @depends testOpenSession
*/
Expand Down

0 comments on commit 7cedc8e

Please sign in to comment.