8000 [Session] Fixed a bug with the TestListener · symfony/symfony@6b9ee87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b9ee87

Browse files
author
Baldur Rensch
committed
[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.
1 parent c6bd807 commit 6b9ee87

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public function onKernelResponse(FilterResponseEvent $event)
6868
}
6969

7070
if ($session = $event->getRequest()->getSession()) {
71-
$session->save();
71+
if ($session->isStarted()) {
72+
$session->save();
73+
}
7274

7375
$params = session_get_cookie_params();
7476

src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected function tearDown()
4343

4444
public function testShouldSaveMasterRequestSession()
4545
{
46+
$this->sessionHasBeenStarted();
4647
$this->sessionMustBeSaved();
4748

4849
$this->filterResponse(new Request());
@@ -66,6 +67,14 @@ public function testDoesNotDeleteCookieIfUsingSessionLifetime()
6667
$this->assertEquals(0, reset($cookies)->getExpiresTime());
6768
}
6869

70+
public function testUnstartedSessionIsNotSave()
71+
{
72+
$this->sessionHasNotBeenStarted();
73+
$this->sessionMustNotBeSaved();
74+
75+
$this->filterResponse(new Request());
76+
}
77+
6978
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
7079
{
7180
$request->setSession($this->session);
@@ -92,6 +101,20 @@ private function sessionMustBeSaved()
92101
->method('save');
93102
}
94103

104+
private function sessionHasBeenStarted()
105+
{
106+
$this->session->expects($this->once())
107+
->method('isStarted' 939D )
108+
->will($this->returnValue(true));
109+
}
110+
111+
private function sessionHasNotBeenStarted()
112+
{
113+
$this->session->expects($this->once())
114+
->method('isStarted')
115+
->will($this->returnValue(false));
116+
}
117+
95118
private function getSession()
96119
{
97120
$mock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')

0 commit comments

Comments
 (0)
0