8000 bug #27350 [HttpKernel] fix deprecation in AbstractTestSessionListene… · symfony/symfony@7d23ac5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d23ac5

Browse files
bug #27350 [HttpKernel] fix deprecation in AbstractTestSessionListener (alekitto)
This PR was merged into the 4.1 branch. Discussion ---------- [HttpKernel] fix deprecation in AbstractTestSessionListener | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT After #26564 functional tests began to emit a deprecation warning because of `getSession()` being called without verifying the existence of a session. Commits ------- 0ecaefe [HttpKernel] fix deprecation in AbstractTestSessionListener
2 parents af62eac + 0ecaefe commit 7d23ac5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public function onKernelResponse(FilterResponseEvent $event)
6161
return;
6262
}
6363

64-
if (!$session = $event->getRequest()->getSession()) {
64+
$request = $event->getRequest();
65+
if (!$request->hasSession()) {
6566
return;
6667
}
6768

69+
$session = $request->getSession();
6870
if ($wasStarted = $session->isStarted()) {
6971
$session->save();
7072
}

src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ public function testDoesNotImplementServiceSubscriberInterface()
123123
$this->assertFalse(is_subclass_of(TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford'));
124124
}
125125

126+
public function testDoesNotThrowIfRequestDoesNotHaveASession()
127+
{
128+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
129+
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response());
130+
131+
$this->listener->onKernelResponse($event);
132+
133+
$this->assertTrue(true);
134+
}
135+
126136
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
127137
{
128138
$request->setSession($this->session);

0 commit comments

Comments
 (0)
0