Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Tobion merged 1 commit intosymfony:masterfromnicolas-grekas:mig-strict
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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;
}
}
Original file line numberDiff line numberDiff 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 functiontestDestroys()
public functiontestDestroy()
{
$sessionId = 'xyz';

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

public functiontestOpens()
public functiontestOpen()
{
$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 functiontestReads()
public functiontestRead()
{
$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 functiontestWrites()
public functiontestWrite()
{
$sessionId = 'xyz';
$data = 'my-serialized-data';
Expand All@@ -138,4 +144,43 @@ public function testWrites()

$this->assertTrue($result);
}

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);
}
}

[8]ページ先頭

©2009-2025 Movatter.jp