菜谱项目

NullSessionHandlerTest.php 1.7KB

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\Storage\Handler\NullSessionHandler;
  13. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  14. use Symfony\Component\HttpFoundation\Session\Session;
  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(array(), new NullSessionHandler());
  51. }
  52. }