NullSessionHandlerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. *
  22. * @preserveGlobalState disabled
  23. */
  24. class NullSessionHandlerTest extends TestCase
  25. {
  26. public function testSaveHandlers()
  27. {
  28. $this->getStorage();
  29. $this->assertEquals('user', \ini_get('session.save_handler'));
  30. }
  31. public function testSession()
  32. {
  33. session_id('nullsessionstorage');
  34. $storage = $this->getStorage();
  35. $session = new Session($storage);
  36. $this->assertNull($session->get('something'));
  37. $session->set('something', 'unique');
  38. $this->assertEquals('unique', $session->get('something'));
  39. }
  40. public function testNothingIsPersisted()
  41. {
  42. session_id('nullsessionstorage');
  43. $storage = $this->getStorage();
  44. $session = new Session($storage);
  45. $session->start();
  46. $this->assertEquals('nullsessionstorage', $session->getId());
  47. $this->assertNull($session->get('something'));
  48. }
  49. public function getStorage()
  50. {
  51. return new NativeSessionStorage([], new NullSessionHandler());
  52. }
  53. }