Skip to content

Commit

Permalink
Fix session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Nov 10, 2022
1 parent b36f749 commit 81b6edf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
12 changes: 11 additions & 1 deletion tests/Fixtures/session/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@
class MockSessionHandler extends \SessionHandler
{
private $data;
private $sessionId;

public function __construct($data = null)
public function __construct($data = '', $sessionId = null)
{
$this->data = $data;
$this->sessionId = $sessionId;
}

public function getData()
Expand Down Expand Up @@ -173,21 +175,29 @@ public function gc($maxLifetime)

protected function doRead($sessionId)
{
if (isset($this->sessionId) && $sessionId !== $this->sessionId) {
echo __FUNCTION__ . ": invalid sessionId\n";

return '';
}
echo __FUNCTION__.': ', $this->data, "\n";
$this->sessionId = $sessionId;

return $this->data;
}

protected function doWrite($sessionId, $data)
{
echo __FUNCTION__.': ', $data, "\n";
$this->sessionId = $sessionId;

return true;
}

protected function doDestroy($sessionId)
{
echo __FUNCTION__, "\n";
$this->sessionId = $sessionId;

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/session/regenerate.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ close
open
validateId
read
doRead: abc|i:123;
doRead: invalid sessionId
read
doRead: abc|i:123;

write
doWrite: abc|i:123;
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/session/regenerate.samesite.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ close
open
validateId
read
doRead: abc|i:123;
doRead: invalid sessionId
read
doRead: abc|i:123;

write
doWrite: abc|i:123;
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/session/regenerate.secure.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ close
open
validateId
read
doRead: abc|i:123;
doRead: invalid sessionId
read
doRead: abc|i:123;

write
doWrite: abc|i:123;
Expand Down

0 comments on commit 81b6edf

Please sign in to comment.