1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; 13 14use PHPUnit\Framework\TestCase; 15use Symfony\Component\HttpFoundation\Session\Session; 16use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler; 17use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; 18 19/** 20 * Test class for NullSessionHandler. 21 * 22 * @author Drak <drak@zikula.org> 23 * 24 * @runTestsInSeparateProcesses 25 * @preserveGlobalState disabled 26 */ 27class NullSessionHandlerTest extends TestCase 28{ 29 public function testSaveHandlers() 30 { 31 $this->getStorage(); 32 $this->assertEquals('user', ini_get('session.save_handler')); 33 } 34 35 public function testSession() 36 { 37 session_id('nullsessionstorage'); 38 $storage = $this->getStorage(); 39 $session = new Session($storage); 40 $this->assertNull($session->get('something')); 41 $session->set('something', 'unique'); 42 $this->assertEquals('unique', $session->get('something')); 43 } 44 45 public function testNothingIsPersisted() 46 { 47 session_id('nullsessionstorage'); 48 $storage = $this->getStorage(); 49 $session = new Session($storage); 50 $session->start(); 51 $this->assertEquals('nullsessionstorage', $session->getId()); 52 $this->assertNull($session->get('something')); 53 } 54 55 public function getStorage() 56 { 57 return new NativeSessionStorage([], new NullSessionHandler()); 58 } 59} 60