fixed an issue with session mocking in functional tests that do not start with a fresh session instance for each request (Silex for instance)

This commit is contained in:
Fabien Potencier 2012-06-12 10:24:12 +02:00
parent 171eecf679
commit 66ff06096c
3 changed files with 8 additions and 3 deletions

View File

@ -42,7 +42,7 @@ class SessionController extends ContainerAware
public function logoutAction()
{
$request = $this->container->get('request')->getSession('session')->clear();
$request = $this->container->get('request')->getSession('session')->invalidate();
return new Response('Session cleared.');
}

View File

@ -93,6 +93,11 @@ class MockFileSessionStorage extends MockArraySessionStorage
public function save()
{
$this->handler->write($this->id, serialize($this->data));
// this is needed for Silex, where the session object is re-used across requests
// in functional tests. In Symfony, the container is rebooted, so we don't have
// this issue
$this->started = false;
}
/**

View File

@ -111,8 +111,8 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase
private function getStorage()
{
$storage = new MockFileSessionStorage($this->sessionDir);
$storage->registerBag(new FlashBag);
$storage->registerBag(new AttributeBag);
$storage->registerBag(new FlashBag());
$storage->registerBag(new AttributeBag());
return $storage;
}