[Session] Fixed a bug with the TestListener
When the session is not started, the test listener would still save the session causing the session data to be emptied.
This commit is contained in:
parent
c6bd807726
commit
6b9ee87b62
@ -68,7 +68,9 @@ class TestSessionListener implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
if ($session = $event->getRequest()->getSession()) {
|
||||
$session->save();
|
||||
if ($session->isStarted()) {
|
||||
$session->save();
|
||||
}
|
||||
|
||||
$params = session_get_cookie_params();
|
||||
|
||||
|
@ -43,6 +43,7 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testShouldSaveMasterRequestSession()
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
$this->sessionMustBeSaved();
|
||||
|
||||
$this->filterResponse(new Request());
|
||||
@ -66,6 +67,14 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(0, reset($cookies)->getExpiresTime());
|
||||
}
|
||||
|
||||
public function testUnstartedSessionIsNotSave()
|
||||
{
|
||||
$this->sessionHasNotBeenStarted();
|
||||
$this->sessionMustNotBeSaved();
|
||||
|
||||
$this->filterResponse(new Request());
|
||||
}
|
||||
|
||||
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
|
||||
{
|
||||
$request->setSession($this->session);
|
||||
@ -92,6 +101,20 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->method('save');
|
||||
}
|
||||
|
||||
private function sessionHasBeenStarted()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('isStarted')
|
||||
->will($this->returnValue(true));
|
||||
}
|
||||
|
||||
private function sessionHasNotBeenStarted()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('isStarted')
|
||||
->will($this->returnValue(false));
|
||||
}
|
||||
|
||||
private function getSession()
|
||||
{
|
||||
$mock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')
|
||||
|
Reference in New Issue
Block a user