PhpBridgeSessionStorageTest.php in Zircon Profile 8
File
vendor/symfony/http-foundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php
View source
<?php
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase {
private $savePath;
protected function setUp() {
$this
->iniSet('session.save_handler', 'files');
$this
->iniSet('session.save_path', $this->savePath = sys_get_temp_dir() . '/sf2test');
if (!is_dir($this->savePath)) {
mkdir($this->savePath);
}
}
protected function tearDown() {
session_write_close();
array_map('unlink', glob($this->savePath . '/*'));
if (is_dir($this->savePath)) {
rmdir($this->savePath);
}
$this->savePath = null;
}
protected function getStorage() {
$storage = new PhpBridgeSessionStorage();
$storage
->registerBag(new AttributeBag());
return $storage;
}
public function testPhpSession53() {
if (PHP_VERSION_ID >= 50400) {
$this
->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
$storage = $this
->getStorage();
$this
->assertFalse(isset($_SESSION));
$this
->assertFalse($storage
->getSaveHandler()
->isActive());
session_start();
$this
->assertTrue(isset($_SESSION));
$this
->assertFalse($storage
->getSaveHandler()
->isActive());
$this
->assertFalse($storage
->isStarted());
$key = $storage
->getMetadataBag()
->getStorageKey();
$this
->assertFalse(isset($_SESSION[$key]));
$storage
->start();
$this
->assertTrue(isset($_SESSION[$key]));
}
public function testPhpSession54() {
if (PHP_VERSION_ID < 50400) {
$this
->markTestSkipped('Test skipped, for PHP 5.4 only.');
}
$storage = $this
->getStorage();
$this
->assertFalse($storage
->getSaveHandler()
->isActive());
$this
->assertFalse($storage
->isStarted());
session_start();
$this
->assertTrue(isset($_SESSION));
$this
->assertTrue($storage
->getSaveHandler()
->isActive());
$this
->assertFalse($storage
->isStarted());
$key = $storage
->getMetadataBag()
->getStorageKey();
$this
->assertFalse(isset($_SESSION[$key]));
$storage
->start();
$this
->assertTrue(isset($_SESSION[$key]));
}
public function testClear() {
$storage = $this
->getStorage();
session_start();
$_SESSION['drak'] = 'loves symfony';
$storage
->getBag('attributes')
->set('symfony', 'greatness');
$key = $storage
->getBag('attributes')
->getStorageKey();
$this
->assertEquals($_SESSION[$key], array(
'symfony' => 'greatness',
));
$this
->assertEquals($_SESSION['drak'], 'loves symfony');
$storage
->clear();
$this
->assertEquals($_SESSION[$key], array());
$this
->assertEquals($_SESSION['drak'], 'loves symfony');
}
}