Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • Symfony\Component\Yaml\Tests\A
  • Symfony\Component\Yaml\Tests\B
  • Symfony\Component\Yaml\Tests\DumperTest
  • Symfony\Component\Yaml\Tests\InlineTest
  • Symfony\Component\Yaml\Tests\ParseExceptionTest
  • Symfony\Component\Yaml\Tests\ParserTest
  • Symfony\Component\Yaml\Tests\YamlTest
  • Overview
  • Namespace
  • Function
  • Tree
  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: 
 12: namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
 13: 
 14: use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
 15: use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
 16: use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
 17: use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
 18: use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
 19: use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
 20: use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
 21: 
 22: /**
 23:  * Test class for NativeSessionStorage.
 24:  *
 25:  * @author Drak <drak@zikula.org>
 26:  *
 27:  * These tests require separate processes.
 28:  *
 29:  * @runTestsInSeparateProcesses
 30:  * @preserveGlobalState disabled
 31:  */
 32: class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
 33: {
 34:     private $savePath;
 35: 
 36:     protected function setUp()
 37:     {
 38:         $this->iniSet('session.save_handler', 'files');
 39:         $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
 40:         if (!is_dir($this->savePath)) {
 41:             mkdir($this->savePath);
 42:         }
 43:     }
 44: 
 45:     protected function tearDown()
 46:     {
 47:         session_write_close();
 48:         array_map('unlink', glob($this->savePath.'/*'));
 49:         if (is_dir($this->savePath)) {
 50:             rmdir($this->savePath);
 51:         }
 52: 
 53:         $this->savePath = null;
 54:     }
 55: 
 56:     /**
 57:      * @param array $options
 58:      *
 59:      * @return NativeSessionStorage
 60:      */
 61:     protected function getStorage(array $options = array())
 62:     {
 63:         $storage = new NativeSessionStorage($options);
 64:         $storage->registerBag(new AttributeBag());
 65: 
 66:         return $storage;
 67:     }
 68: 
 69:     public function testBag()
 70:     {
 71:         $storage = $this->getStorage();
 72:         $bag = new FlashBag();
 73:         $storage->registerBag($bag);
 74:         $this->assertSame($bag, $storage->getBag($bag->getName()));
 75:     }
 76: 
 77:     /**
 78:      * @expectedException \InvalidArgumentException
 79:      */
 80:     public function testRegisterBagException()
 81:     {
 82:         $storage = $this->getStorage();
 83:         $storage->getBag('non_existing');
 84:     }
 85: 
 86:     public function testGetId()
 87:     {
 88:         $storage = $this->getStorage();
 89:         $this->assertSame('', $storage->getId(), 'Empty ID before starting session');
 90: 
 91:         $storage->start();
 92:         $id = $storage->getId();
 93:         $this->assertInternalType('string', $id);
 94:         $this->assertNotSame('', $id);
 95: 
 96:         $storage->save();
 97:         $this->assertSame($id, $storage->getId(), 'ID stays after saving session');
 98:     }
 99: 
100:     public function testRegenerate()
101:     {
102:         $storage = $this->getStorage();
103:         $storage->start();
104:         $id = $storage->getId();
105:         $storage->getBag('attributes')->set('lucky', 7);
106:         $storage->regenerate();
107:         $this->assertNotEquals($id, $storage->getId());
108:         $this->assertEquals(7, $storage->getBag('attributes')->get('lucky'));
109:     }
110: 
111:     public function testRegenerateDestroy()
112:     {
113:         $storage = $this->getStorage();
114:         $storage->start();
115:         $id = $storage->getId();
116:         $storage->getBag('attributes')->set('legs', 11);
117:         $storage->regenerate(true);
118:         $this->assertNotEquals($id, $storage->getId());
119:         $this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
120:     }
121: 
122:     public function testDefaultSessionCacheLimiter()
123:     {
124:         $this->iniSet('session.cache_limiter', 'nocache');
125: 
126:         $storage = new NativeSessionStorage();
127:         $this->assertEquals('', ini_get('session.cache_limiter'));
128:     }
129: 
130:     public function testExplicitSessionCacheLimiter()
131:     {
132:         $this->iniSet('session.cache_limiter', 'nocache');
133: 
134:         $storage = new NativeSessionStorage(array('cache_limiter' => 'public'));
135:         $this->assertEquals('public', ini_get('session.cache_limiter'));
136:     }
137: 
138:     public function testCookieOptions()
139:     {
140:         $options = array(
141:             'cookie_lifetime' => 123456,
142:             'cookie_path' => '/my/cookie/path',
143:             'cookie_domain' => 'symfony.example.com',
144:             'cookie_secure' => true,
145:             'cookie_httponly' => false,
146:         );
147: 
148:         $this->getStorage($options);
149:         $temp = session_get_cookie_params();
150:         $gco = array();
151: 
152:         foreach ($temp as $key => $value) {
153:             $gco['cookie_'.$key] = $value;
154:         }
155: 
156:         $this->assertEquals($options, $gco);
157:     }
158: 
159:     /**
160:      * @expectedException \InvalidArgumentException
161:      */
162:     public function testSetSaveHandlerException()
163:     {
164:         $storage = $this->getStorage();
165:         $storage->setSaveHandler(new \stdClass());
166:     }
167: 
168:     public function testSetSaveHandler53()
169:     {
170:         if (PHP_VERSION_ID >= 50400) {
171:             $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
172:         }
173: 
174:         $this->iniSet('session.save_handler', 'files');
175:         $storage = $this->getStorage();
176:         $storage->setSaveHandler();
177:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
178:         $storage->setSaveHandler(null);
179:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
180:         $storage->setSaveHandler(new NativeSessionHandler());
181:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
182:         $storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
183:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
184:         $storage->setSaveHandler(new NullSessionHandler());
185:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
186:         $storage->setSaveHandler(new NativeProxy());
187:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
188:     }
189: 
190:     public function testSetSaveHandler54()
191:     {
192:         if (PHP_VERSION_ID < 50400) {
193:             $this->markTestSkipped('Test skipped, for PHP 5.4 only.');
194:         }
195: 
196:         $this->iniSet('session.save_handler', 'files');
197:         $storage = $this->getStorage();
198:         $storage->setSaveHandler();
199:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
200:         $storage->setSaveHandler(null);
201:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
202:         $storage->setSaveHandler(new SessionHandlerProxy(new NativeSessionHandler()));
203:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
204:         $storage->setSaveHandler(new NativeSessionHandler());
205:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
206:         $storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
207:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
208:         $storage->setSaveHandler(new NullSessionHandler());
209:         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
210:     }
211: 
212:     /**
213:      * @expectedException \RuntimeException
214:      */
215:     public function testStartedOutside()
216:     {
217:         $storage = $this->getStorage();
218: 
219:         $this->assertFalse(isset($_SESSION));
220:         $this->assertFalse($storage->getSaveHandler()->isActive());
221:         $this->assertFalse($storage->isStarted());
222: 
223:         session_start();
224:         $this->assertTrue(isset($_SESSION));
225:         if (PHP_VERSION_ID >= 50400) {
226:             // this only works in PHP >= 5.4 where session_status is available
227:             $this->assertTrue($storage->getSaveHandler()->isActive());
228:         }
229:         // PHP session might have started, but the storage driver has not, so false is correct here
230:         $this->assertFalse($storage->isStarted());
231: 
232:         $key = $storage->getMetadataBag()->getStorageKey();
233:         $this->assertFalse(isset($_SESSION[$key]));
234:         $storage->start();
235:     }
236: 
237:     public function testRestart()
238:     {
239:         $storage = $this->getStorage();
240:         $storage->start();
241:         $id = $storage->getId();
242:         $storage->getBag('attributes')->set('lucky', 7);
243:         $storage->save();
244:         $storage->start();
245:         $this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
246:         $this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
247:     }
248: }
249: 
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen