This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockFileSessionStorageTest.php

100 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace Symfony\Test\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\MockFileSessionStorage;
/**
* Test class for MockFileSessionStorage.
*
* @author Drak <drak@zikula.org>
*/
class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase
{
/**
* @var string
*/
private $sessionDir;
/**
* @var FileMockSessionStorage
*/
protected $storage;
protected function setUp()
{
$this->sessionDir = sys_get_temp_dir().'/sf2test';
$this->storage = $this->getStorage();
}
protected function tearDown()
{
$this->sessionDir = null;
$this->storage = null;
array_map('unlink', glob($this->sessionDir.'/*.session'));
if (is_dir($this->sessionDir)) {
rmdir($this->sessionDir);
}
}
public function testStart()
{
$this->assertEquals('', $this->storage->getId());
$this->assertTrue($this->storage->start());
$id = $this->storage->getId();
$this->assertNotEquals('', $this->storage->getId());
$this->assertTrue($this->storage->start());
$this->assertEquals($id, $this->storage->getId());
}
public function testRegenerate()
{
$this->storage->start();
$this->storage->getAttributes()->set('regenerate', 1234);
$this->storage->regenerate();
$this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate'));
$this->storage->regenerate(true);
$this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate'));
}
public function testGetId()
{
$this->assertEquals('', $this->storage->getId());
$this->storage->start();
$this->assertNotEquals('', $this->storage->getId());
}
public function testSave()
{
$this->storage->start();
$this->assertNotEquals('108', $this->storage->getAttributes()->get('new'));
$this->assertFalse($this->storage->getFlashes()->has('newkey'));
$this->storage->getAttributes()->set('new', '108');
$this->storage->getFlashes()->set('newkey', 'test');
$this->storage->save();
$storage = $this->getStorage();
$storage->start();
$this->assertEquals('108', $storage->getAttributes()->get('new'));
$this->assertTrue($storage->getFlashes()->has('newkey'));
$this->assertEquals('test', $storage->getFlashes()->get('newkey'));
}
public function testMultipleInstances()
{
$storage1 = $this->getStorage();
$storage1->start();
$storage1->getAttributes()->set('foo', 'bar');
$storage1->save();
$storage2 = $this->getStorage();
$storage2->start();
$this->assertEquals('bar', $storage2->getAttributes()->get('foo'), 'values persist between instances');
}
private function getStorage(array $options = array())
{
return new MockFileSessionStorage($this->sessionDir, $options);
}
}