merged branch drak/frameworktestsession (PR #6369)

This PR was merged into the 2.1 branch.

Commits
-------

54d3f81 [FrameworkBundle] Fixed logic under test environment.

Discussion
----------

[FrameworkBundle] Fixed logic under test environment.

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets:-
Todo: -
License of the code: MIT
Documentation PR: -

Please note the travis build failed on some Forms stuff which is nothing to do with this PR.
This commit is contained in:
Fabien Potencier 2012-12-15 17:25:40 +01:00
commit 021de7270a
2 changed files with 13 additions and 6 deletions

View File

@ -67,13 +67,10 @@ class TestSessionListener implements EventSubscriberInterface
return; return;
} }
if ($session = $event->getRequest()->getSession()) { $session = $event->getRequest()->getSession();
if ($session->isStarted()) { if ($session && $session->isStarted()) {
$session->save(); $session->save();
}
$params = session_get_cookie_params(); $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'])); $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\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/** /**
* SessionListenerTest. * SessionListenerTest.
@ -26,7 +27,14 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
*/ */
class TestSessionListenerTest extends \PHPUnit_Framework_TestCase class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var TestSessionListener
*/
private $listener; private $listener;
/**
* @var SessionInterface
*/
private $session; private $session;
protected function setUp() protected function setUp()
@ -58,6 +66,8 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
public function testDoesNotDeleteCookieIfUsingSessionLifetime() public function testDoesNotDeleteCookieIfUsingSessionLifetime()
{ {
$this->sessionHasBeenStarted();
$params = session_get_cookie_params(); $params = session_get_cookie_params();
session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']); session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);