1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
13:
14: use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
15: use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
28: {
29: private $savePath;
30:
31: protected function setUp()
32: {
33: $this->iniSet('session.save_handler', 'files');
34: $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
35: if (!is_dir($this->savePath)) {
36: mkdir($this->savePath);
37: }
38: }
39:
40: protected function tearDown()
41: {
42: session_write_close();
43: array_map('unlink', glob($this->savePath.'/*'));
44: if (is_dir($this->savePath)) {
45: rmdir($this->savePath);
46: }
47:
48: $this->savePath = null;
49: }
50:
51: 52: 53:
54: protected function getStorage()
55: {
56: $storage = new PhpBridgeSessionStorage();
57: $storage->registerBag(new AttributeBag());
58:
59: return $storage;
60: }
61:
62: public function testPhpSession53()
63: {
64: if (PHP_VERSION_ID >= 50400) {
65: $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
66: }
67:
68: $storage = $this->getStorage();
69:
70: $this->assertFalse(isset($_SESSION));
71: $this->assertFalse($storage->getSaveHandler()->isActive());
72:
73: session_start();
74: $this->assertTrue(isset($_SESSION));
75:
76: $this->assertFalse($storage->getSaveHandler()->isActive());
77:
78: $this->assertFalse($storage->isStarted());
79:
80: $key = $storage->getMetadataBag()->getStorageKey();
81: $this->assertFalse(isset($_SESSION[$key]));
82: $storage->start();
83: $this->assertTrue(isset($_SESSION[$key]));
84: }
85:
86: public function testPhpSession54()
87: {
88: if (PHP_VERSION_ID < 50400) {
89: $this->markTestSkipped('Test skipped, for PHP 5.4 only.');
90: }
91:
92: $storage = $this->getStorage();
93:
94: $this->assertFalse(isset($_SESSION));
95: $this->assertFalse($storage->getSaveHandler()->isActive());
96: $this->assertFalse($storage->isStarted());
97:
98: session_start();
99: $this->assertTrue(isset($_SESSION));
100:
101: $this->assertTrue($storage->getSaveHandler()->isActive());
102:
103: $this->assertFalse($storage->isStarted());
104:
105: $key = $storage->getMetadataBag()->getStorageKey();
106: $this->assertFalse(isset($_SESSION[$key]));
107: $storage->start();
108: $this->assertTrue(isset($_SESSION[$key]));
109: }
110:
111: public function testClear()
112: {
113: $storage = $this->getStorage();
114: session_start();
115: $_SESSION['drak'] = 'loves symfony';
116: $storage->getBag('attributes')->set('symfony', 'greatness');
117: $key = $storage->getBag('attributes')->getStorageKey();
118: $this->assertEquals($_SESSION[$key], array('symfony' => 'greatness'));
119: $this->assertEquals($_SESSION['drak'], 'loves symfony');
120: $storage->clear();
121: $this->assertEquals($_SESSION[$key], array());
122: $this->assertEquals($_SESSION['drak'], 'loves symfony');
123: }
124: }
125: