4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
16 use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17 use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
20 * Test class for MockArraySessionStorage.
22 * @author Drak <drak@zikula.org>
24 class MockArraySessionStorageTest extends TestCase
27 * @var MockArraySessionStorage
43 protected function setUp()
45 $this->attributes = new AttributeBag();
46 $this->flashes = new FlashBag();
49 $this->attributes->getStorageKey() => array('foo' => 'bar'),
50 $this->flashes->getStorageKey() => array('notice' => 'hello'),
53 $this->storage = new MockArraySessionStorage();
54 $this->storage->registerBag($this->flashes);
55 $this->storage->registerBag($this->attributes);
56 $this->storage->setSessionData($this->data);
59 protected function tearDown()
62 $this->flashes = null;
63 $this->attributes = null;
64 $this->storage = null;
67 public function testStart()
69 $this->assertEquals('', $this->storage->getId());
70 $this->storage->start();
71 $id = $this->storage->getId();
72 $this->assertNotEquals('', $id);
73 $this->storage->start();
74 $this->assertEquals($id, $this->storage->getId());
77 public function testRegenerate()
79 $this->storage->start();
80 $id = $this->storage->getId();
81 $this->storage->regenerate();
82 $this->assertNotEquals($id, $this->storage->getId());
83 $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
84 $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
86 $id = $this->storage->getId();
87 $this->storage->regenerate(true);
88 $this->assertNotEquals($id, $this->storage->getId());
89 $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
90 $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
93 public function testGetId()
95 $this->assertEquals('', $this->storage->getId());
96 $this->storage->start();
97 $this->assertNotEquals('', $this->storage->getId());
100 public function testClearClearsBags()
102 $this->storage->clear();
104 $this->assertSame(array(), $this->storage->getBag('attributes')->all());
105 $this->assertSame(array(), $this->storage->getBag('flashes')->peekAll());
108 public function testClearStartsSession()
110 $this->storage->clear();
112 $this->assertTrue($this->storage->isStarted());
115 public function testClearWithNoBagsStartsSession()
117 $storage = new MockArraySessionStorage();
121 $this->assertTrue($storage->isStarted());
125 * @expectedException \RuntimeException
127 public function testUnstartedSave()
129 $this->storage->save();