Open Journal Systems  3.3.0
PhpBridgeSessionStorageTest.php
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 
13 
14 use PHPUnit\Framework\TestCase;
17 
28 class PhpBridgeSessionStorageTest extends TestCase
29 {
30  private $savePath;
31 
32  protected function setUp()
33  {
34  $this->iniSet('session.save_handler', 'files');
35  $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
36  if (!is_dir($this->savePath)) {
37  mkdir($this->savePath);
38  }
39  }
40 
41  protected function tearDown()
42  {
43  session_write_close();
44  array_map('unlink', glob($this->savePath.'/*'));
45  if (is_dir($this->savePath)) {
46  rmdir($this->savePath);
47  }
48 
49  $this->savePath = null;
50  }
51 
55  protected function getStorage()
56  {
58  $storage->registerBag(new AttributeBag());
59 
60  return $storage;
61  }
62 
63  public function testPhpSession()
64  {
65  $storage = $this->getStorage();
66 
67  $this->assertFalse($storage->getSaveHandler()->isActive());
68  $this->assertFalse($storage->isStarted());
69 
70  session_start();
71  $this->assertTrue(isset($_SESSION));
72  // in PHP 5.4 we can reliably detect a session started
73  $this->assertTrue($storage->getSaveHandler()->isActive());
74  // PHP session might have started, but the storage driver has not, so false is correct here
75  $this->assertFalse($storage->isStarted());
76 
77  $key = $storage->getMetadataBag()->getStorageKey();
78  $this->assertFalse(isset($_SESSION[$key]));
79  $storage->start();
80  $this->assertTrue(isset($_SESSION[$key]));
81  }
82 
83  public function testClear()
84  {
85  $storage = $this->getStorage();
86  session_start();
87  $_SESSION['drak'] = 'loves symfony';
88  $storage->getBag('attributes')->set('symfony', 'greatness');
89  $key = $storage->getBag('attributes')->getStorageKey();
90  $this->assertEquals($_SESSION[$key], array('symfony' => 'greatness'));
91  $this->assertEquals($_SESSION['drak'], 'loves symfony');
92  $storage->clear();
93  $this->assertEquals($_SESSION[$key], array());
94  $this->assertEquals($_SESSION['drak'], 'loves symfony');
95  }
96 }
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest\tearDown
tearDown()
Definition: PhpBridgeSessionStorageTest.php:41
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest\testPhpSession
testPhpSession()
Definition: PhpBridgeSessionStorageTest.php:63
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest\testClear
testClear()
Definition: PhpBridgeSessionStorageTest.php:83
Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage
Definition: lib/vendor/symfony/http-foundation/Session/Storage/PhpBridgeSessionStorage.php:22
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest\setUp
setUp()
Definition: PhpBridgeSessionStorageTest.php:32
Symfony\Component\HttpFoundation\Session\Session\$storage
$storage
Definition: lib/vendor/symfony/http-foundation/Session/Session.php:37
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest
Definition: PhpBridgeSessionStorageTest.php:28
Symfony\Component\HttpFoundation\Tests\Session\Storage
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag
Definition: lib/vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:17
Symfony\Component\HttpFoundation\Tests\Session\Storage\PhpBridgeSessionStorageTest\getStorage
getStorage()
Definition: PhpBridgeSessionStorageTest.php:55