FilesystemSessionStorageTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Tests\Component\HttpFoundation\SessionStorage;
  11. use Symfony\Component\HttpFoundation\SessionStorage\FilesystemSessionStorage;
  12. class FilesystemSessionStorageTest extends \PHPUnit_Framework_TestCase
  13. {
  14. private $path;
  15. protected function setUp()
  16. {
  17. $this->path = sys_get_temp_dir().'/sf2/session_test';
  18. if (!file_exists($this->path)) {
  19. mkdir($this->path, 0777, true);
  20. }
  21. }
  22. protected function tearDown()
  23. {
  24. array_map('unlink', glob($this->path.'/*.session'));
  25. rmdir($this->path);
  26. }
  27. public function testMultipleInstances()
  28. {
  29. $storage = new FilesystemSessionStorage($this->path);
  30. $storage->start();
  31. $storage->write('foo', 'bar');
  32. $storage = new FilesystemSessionStorage($this->path);
  33. $storage->start();
  34. $this->assertEquals('bar', $storage->read('foo'), 'values persist between instances');
  35. }
  36. public function testGetIdThrowsErrorBeforeStart()
  37. {
  38. $this->setExpectedException('RuntimeException');
  39. $storage = new FilesystemSessionStorage($this->path);
  40. $storage->getId();
  41. }
  42. public function testGetIdWorksAfterStart()
  43. {
  44. $storage = new FilesystemSessionStorage($this->path);
  45. $storage->start();
  46. $storage->getId();
  47. }
  48. }