PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php

https://bitbucket.org/Leimz/leimzwebsite
PHP | 104 lines | 69 code | 27 blank | 8 comment | 1 complexity | 83658aada61fe7d43f0fe289ff7f0d4a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause, BSD-3-Clause
  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. $this->path = null;
  27. }
  28. public function testMultipleInstances()
  29. {
  30. $storage1 = new FilesystemSessionStorage($this->path);
  31. $storage1->start();
  32. $storage1->write('foo', 'bar');
  33. $storage2 = new FilesystemSessionStorage($this->path);
  34. $storage2->start();
  35. $this->assertEquals('bar', $storage2->read('foo'), 'values persist between instances');
  36. }
  37. public function testGetIdThrowsErrorBeforeStart()
  38. {
  39. $this->setExpectedException('RuntimeException');
  40. $storage = new FilesystemSessionStorage($this->path);
  41. $storage->getId();
  42. }
  43. public function testGetIdWorksAfterStart()
  44. {
  45. $storage = new FilesystemSessionStorage($this->path);
  46. $storage->start();
  47. $storage->getId();
  48. }
  49. public function testGetIdSetByOptions()
  50. {
  51. $previous = ini_get('session.use_cookies');
  52. ini_set('session.use_cookies', false);
  53. $storage = new FilesystemSessionStorage($this->path, array('id' => 'symfony2-sessionId'));
  54. $storage->start();
  55. $this->assertEquals('symfony2-sessionId', $storage->getId());
  56. ini_set('session.use_cookies', $previous);
  57. }
  58. public function testRemoveVariable()
  59. {
  60. $storage = new FilesystemSessionStorage($this->path);
  61. $storage->start();
  62. $storage->write('foo', 'bar');
  63. $this->assertEquals('bar', $storage->read('foo'));
  64. $storage->remove('foo', 'bar');
  65. $this->assertNull($storage->read('foo'));
  66. }
  67. public function testRegenerate()
  68. {
  69. $storage = new FilesystemSessionStorage($this->path);
  70. $storage->start();
  71. $storage->write('foo', 'bar');
  72. $storage->regenerate();
  73. $this->assertEquals('bar', $storage->read('foo'));
  74. $storage->regenerate(true);
  75. $this->assertNull($storage->read('foo'));
  76. }
  77. }