No Description

MockArraySessionStorageTest.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
  11. use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
  12. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  13. use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  14. /**
  15. * Test class for MockArraySessionStorage.
  16. *
  17. * @author Drak <drak@zikula.org>
  18. */
  19. class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
  20. {
  21. /**
  22. * @var MockArraySessionStorage
  23. */
  24. private $storage;
  25. /**
  26. * @var AttributeBag
  27. */
  28. private $attributes;
  29. /**
  30. * @var FlashBag
  31. */
  32. private $flashes;
  33. private $data;
  34. protected function setUp()
  35. {
  36. $this->attributes = new AttributeBag();
  37. $this->flashes = new FlashBag();
  38. $this->data = array(
  39. $this->attributes->getStorageKey() => array('foo' => 'bar'),
  40. $this->flashes->getStorageKey() => array('notice' => 'hello'),
  41. );
  42. $this->storage = new MockArraySessionStorage();
  43. $this->storage->registerBag($this->flashes);
  44. $this->storage->registerBag($this->attributes);
  45. $this->storage->setSessionData($this->data);
  46. }
  47. protected function tearDown()
  48. {
  49. $this->data = null;
  50. $this->flashes = null;
  51. $this->attributes = null;
  52. $this->storage = null;
  53. }
  54. public function testStart()
  55. {
  56. $this->assertEquals('', $this->storage->getId());
  57. $this->storage->start();
  58. $id = $this->storage->getId();
  59. $this->assertNotEquals('', $id);
  60. $this->storage->start();
  61. $this->assertEquals($id, $this->storage->getId());
  62. }
  63. public function testRegenerate()
  64. {
  65. $this->storage->start();
  66. $id = $this->storage->getId();
  67. $this->storage->regenerate();
  68. $this->assertNotEquals($id, $this->storage->getId());
  69. $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
  70. $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
  71. $id = $this->storage->getId();
  72. $this->storage->regenerate(true);
  73. $this->assertNotEquals($id, $this->storage->getId());
  74. $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
  75. $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
  76. }
  77. public function testGetId()
  78. {
  79. $this->assertEquals('', $this->storage->getId());
  80. $this->storage->start();
  81. $this->assertNotEquals('', $this->storage->getId());
  82. }
  83. /**
  84. * @expectedException \RuntimeException
  85. */
  86. public function testUnstartedSave()
  87. {
  88. $this->storage->save();
  89. }
  90. }