From c4a5b67a5af04bfd57b9b203ee2685cf33b42d90 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Mar 2016 08:50:24 +0100 Subject: [PATCH] exception when registering bags for started sessions --- .../Session/Storage/NativeSessionStorage.php | 4 ++++ .../Tests/Session/Storage/NativeSessionStorageTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 137f0e8e1c..aa4a237cdd 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -260,6 +260,10 @@ class NativeSessionStorage implements SessionStorageInterface */ public function registerBag(SessionBagInterface $bag) { + if ($this->started) { + throw new \LogicException('Cannot register a bag when the session is already started.'); + } + $this->bags[$bag->getName()] = $bag; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 121cff37a1..160b575862 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -83,6 +83,16 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase $storage->getBag('non_existing'); } + /** + * @expectedException \LogicException + */ + public function testRegisterBagForAStartedSessionThrowsException() + { + $storage = $this->getStorage(); + $storage->start(); + $storage->registerBag(new AttributeBag()); + } + public function testGetId() { $storage = $this->getStorage();