From e46ef76cb93d883fc002e25d47a2d5edb6c70cef Mon Sep 17 00:00:00 2001 From: David Maicher Date: Thu, 21 Mar 2019 09:24:23 +0100 Subject: [PATCH] [FrameworkBundle][HttpFoundation] make session service resettable --- .../FrameworkBundle/Resources/config/session.xml | 1 + src/Symfony/Bundle/FrameworkBundle/composer.json | 2 +- .../Component/HttpFoundation/Session/Session.php | 4 +++- .../HttpFoundation/Tests/Session/SessionTest.php | 10 ++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml index 8b68d9e846dd..c87f688c7866 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml @@ -15,6 +15,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 78d7ae1e564e..e5449ff32ef7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -23,7 +23,7 @@ "symfony/dependency-injection": "^3.4.24|^4.2.5", "symfony/config": "~3.4|~4.0", "symfony/event-dispatcher": "~3.4|~4.0", - "symfony/http-foundation": "^3.3.11|~4.0", + "symfony/http-foundation": "^3.4.24|^4.2.5", "symfony/http-kernel": "~3.4|~4.0", "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "~2.8|~3.0|~4.0", diff --git a/src/Symfony/Component/HttpFoundation/Session/Session.php b/src/Symfony/Component/HttpFoundation/Session/Session.php index 867ceba97f8d..62ce948b6828 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session/Session.php @@ -193,7 +193,9 @@ public function migrate($destroy = false, $lifetime = null) */ public function save() { - $this->storage->save(); + if ($this->isStarted()) { + $this->storage->save(); + } } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php index afa00fc7c304..e75b3321b035 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php @@ -260,4 +260,14 @@ public function testIsEmpty() $flash->get('hello'); $this->assertTrue($this->session->isEmpty()); } + + public function testSaveIfNotStarted() + { + $storage = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface')->getMock(); + $session = new Session($storage); + + $storage->expects($this->once())->method('isStarted')->willReturn(false); + $storage->expects($this->never())->method('save'); + $session->save(); + } }