NullSessionHandlerTest.php 1.7 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\Component\HttpFoundation\Tests\Session\Storage\Handler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Session\Session;
  13. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
  14. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  15. /**
  16. * Test class for NullSessionHandler.
  17. *
  18. * @author Drak <drak@zikula.org>
  19. *
  20. * @runTestsInSeparateProcesses
  21. * @preserveGlobalState disabled
  22. */
  23. class NullSessionHandlerTest extends TestCase
  24. {
  25. public function testSaveHandlers()
  26. {
  27. $storage = $this->getStorage();
  28. $this->assertEquals('user', ini_get('session.save_handler'));
  29. }
  30. public function testSession()
  31. {
  32. session_id('nullsessionstorage');
  33. $storage = $this->getStorage();
  34. $session = new Session($storage);
  35. $this->assertNull($session->get('something'));
  36. $session->set('something', 'unique');
  37. $this->assertEquals('unique', $session->get('something'));
  38. }
  39. public function testNothingIsPersisted()
  40. {
  41. session_id('nullsessionstorage');
  42. $storage = $this->getStorage();
  43. $session = new Session($storage);
  44. $session->start();
  45. $this->assertEquals('nullsessionstorage', $session->getId());
  46. $this->assertNull($session->get('something'));
  47. }
  48. public function getStorage()
  49. {
  50. return new NativeSessionStorage([], new NullSessionHandler());
  51. }
  52. }