Skip to content

Commit

Permalink
[HttpFoundation] Fix session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 12, 2022
1 parent 7eea76a commit cd4f478
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 12 additions & 2 deletions Tests/Session/Storage/Handler/Fixtures/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ ob_start();
class TestSessionHandler extends AbstractSessionHandler
{
private $data;
private $sessionId;

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

public function open($path, $name): bool
Expand Down Expand Up @@ -131,21 +133,29 @@ class TestSessionHandler extends AbstractSessionHandler

protected function doRead($sessionId): string
{
echo __FUNCTION__.': ', $this->data, "\n";
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): bool
{
echo __FUNCTION__.': ', $data, "\n";
$this->sessionId = $sessionId;

return true;
}

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

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/Session/Storage/Handler/Fixtures/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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ close
open
validateId
read
doRead:
doRead: invalid sessionId
read

write
Expand Down

0 comments on commit cd4f478

Please sign in to comment.