From e5e2d5ddd2753ef24a2fdb73d8626a58f162b213 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 9 Jan 2018 14:54:39 +0100 Subject: [PATCH] [HttpFoundation] Always call proxied handler::destroy() in StrictSessionHandler --- .../Storage/Handler/StrictSessionHandler.php | 14 ++++++++++++++ .../Storage/Handler/StrictSessionHandlerTest.php | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php index 1bad0641e81b..228119297d85 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php @@ -19,6 +19,7 @@ class StrictSessionHandler extends AbstractSessionHandler { private $handler; + private $doDestroy; public function __construct(\SessionHandlerInterface $handler) { @@ -63,11 +64,24 @@ protected function doWrite($sessionId, $data) return $this->handler->write($sessionId, $data); } + /** + * {@inheritdoc} + */ + public function destroy($sessionId) + { + $this->doDestroy = true; + $destroyed = parent::destroy($sessionId); + + return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed; + } + /** * {@inheritdoc} */ protected function doDestroy($sessionId) { + $this->doDestroy = false; + return $this->handler->destroy($sessionId); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php index 8e978487632e..b02c41ae8986 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php @@ -118,7 +118,7 @@ public function testWriteEmptyNewSession() $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); $handler->expects($this->never())->method('write'); - $handler->expects($this->never())->method('destroy'); + $handler->expects($this->once())->method('destroy')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertFalse($proxy->validateId('id')); @@ -154,7 +154,7 @@ public function testDestroyNewSession() $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); - $handler->expects($this->never())->method('destroy'); + $handler->expects($this->once())->method('destroy')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertSame('', $proxy->read('id'));