8000 [HttpFoundation] Have MigratingSessionHandler implement SessionUpdateTimestampHandlerInterface by nicolas-grekas · Pull Request #26828 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Have MigratingSessionHandler implement SessionUpdateTimestampHandlerInterface #26828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpFoundation] Have MigratingSessionHandler implement SessionUpdate…
…TimestampHandlerInterface
  • Loading branch information
nicolas-grekas committed Apr 7, 2018
commit 5d7117bf0a3a25875b8a9df968e8b0148560dac0
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@
* @author Ross Motley <ross.motley@amara.com>
* @author Oliver Radwell <oliver.radwell@amara.com>
*/
class MigratingSessionHandler implements \SessionHandlerInterface
class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
{
private $currentHandler;
private $writeOnlyHandler;

public function __construct(\SessionHandlerInterface $currentHandler, \SessionHandlerInterface $writeOnlyHandler)
{
if (!$currentHandler instanceof \SessionUpdateTimestampHandlerInterface) {
$currentHandler = new StrictSessionHandler($currentHandler);
}
if (!$writeOnlyHandler instanceof \SessionUpdateTimestampHandlerInterface) {
$writeOnlyHandler = new StrictSessionHandler($writeOnlyHandler);
}

$this->currentHandler = $currentHandler;
$this->writeOnlyHandler = $writeOnlyHandler;
}
Expand Down Expand Up @@ -67,10 +74,10 @@ public function gc($maxlifetime)
/**
* {@inheritdoc}
*/
public function open($savePath, $sessionId)
public function open($savePath, $sessionName)
{
$result = $this->currentHandler->open($savePath, $sessionId);
$this->writeOnlyHandler->open($savePath, $sessionId);
$result = $this->currentHandler->open($savePath, $sessionName);
$this->writeOnlyHandler->open($savePath, $sessionName);

return $result;
}
Expand All @@ -94,4 +101,24 @@ public function write($sessionId, $sessionData)

return $result;
}

/**
* {@inheritdoc}
*/
public function validateId($sessionId)
{
// No reading from new handler until switch-over
return $this->currentHandler->validateId($sessionId);
}

/**
* {@inheritdoc}
*/
public function updateTimestamp($sessionId, $sessionData)
{
$result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);
$this->writeOnlyHandler->updateTimestamp($sessionId, $sessionData);

return $result;
}
}
8000
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ protected function setUp()
$this->dualHandler = new MigratingSessionHandler($this->currentHandler, $this->writeOnlyHandler);
}

public function testCloses()
public function testInstanceOf()
{
$this->assertInstanceOf(\SessionHandlerInterface::class, $this->dualHandler);
$this->assertInstanceOf(\SessionUpdateTimestampHandlerInterface::class, $this->dualHandler);
}

public function testClose()
{
$this->currentHandler->expects($this->once())
->method('close')
Expand All @@ -43,7 +49,7 @@ public function testCloses()
$this->assertTrue($result);
}

public function testDestroys()
public function testDestroy()
{
$sessionId = 'xyz';

Expand Down Expand Up @@ -80,27 +86,27 @@ public function testGc()
$this->assertTrue($result);
}

public function testOpens()
public function testOpen()
{
$savePath = '/path/to/save/location';
$sessionId = 'xyz';
$sessionName = 'xyz';

$this->currentHandler->expects($this->once())
->method('open')
->with($savePath, $sessionId)
->with($savePath, $sessionName)
->will($this->returnValue(true));

$this->writeOnlyHandler->expects($this->once())
->method('open')
->with($savePath, $sessionId)
->with($savePath, $sessionName)
->will($this->returnValue(false));

$result = $this->dualHandler->open($savePath, $sessionId);
$result = $this->dualHandler->open($savePath, $sessionName);

$this->assertTrue($result);
}

public function testReads()
public function testRead()
{
$sessionId = 'xyz';
$readValue = 'something';
Expand All @@ -116,10 +122,10 @@ public function testReads()

$result = $this->dualHandler->read($sessionId);

$this->assertEquals($readValue, $result);
$this->assertSame($readValue, $result);
}

public function testWrites()
public function testWrite()
{
$sessionId = 'xyz';
$data = 'my-serialized-data';
Expand All @@ -138,4 +144,43 @@ public function testWrites()

$this->assertTrue($result);
}
< 8000 /td>
public function testValidateId()
{
$sessionId = 'xyz';
$readValue = 'something';

$this->currentHandler->expects($this->once())
->method('read')
->with($sessionId)
->will($this->returnValue($readValue));

$this->writeOnlyHandler->expects($this->never())
->method('read')
->with($this->any());

$result = $this->dualHandler->validateId($sessionId);

$this->assertTrue($result);
}

public function testUpdateTimestamp()
{
$sessionId = 'xyz';
$data = 'my-serialized-data';

$this->currentHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(true));

$this->writeOnlyHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(false));

$result = $this->dualHandler->updateTimestamp($sessionId, $data);

$this->assertTrue($result);
}
}
0