[FrameworkBundle] Fixed logic under test environment.

This commit is contained in:
Drak 2012-12-15 15:16:34 +00:00
parent c67ddb27b3
commit 54d3f814ec
2 changed files with 13 additions and 6 deletions

View File

@ -67,13 +67,10 @@ class TestSessionListener implements EventSubscriberInterface
return;
}
if ($session = $event->getRequest()->getSession()) {
if ($session->isStarted()) {
$session->save();
}
$session = $event->getRequest()->getSession();
if ($session && $session->isStarted()) {
$session->save();
$params = session_get_cookie_params();
$event->getResponse()->headers->setCookie(new Cookie($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']));
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
* SessionListenerTest.
@ -26,7 +27,14 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
*/
class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TestSessionListener
*/
private $listener;
/**
* @var SessionInterface
*/
private $session;
protected function setUp()
@ -58,6 +66,8 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
public function testDoesNotDeleteCookieIfUsingSessionLifetime()
{
$this->sessionHasBeenStarted();
$params = session_get_cookie_params();
session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);