From 0ecaefe17954c44d0e1f1b058e3dc85d43aa0d4e Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Wed, 23 May 2018 10:10:33 +0200 Subject: [PATCH] [HttpKernel] fix deprecation in AbstractTestSessionListener --- .../EventListener/AbstractTestSessionListener.php | 4 +++- .../Tests/EventListener/TestSessionListenerTest.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php index 82061fd6ea..f07647f8a6 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php @@ -61,10 +61,12 @@ abstract class AbstractTestSessionListener implements EventSubscriberInterface return; } - if (!$session = $event->getRequest()->getSession()) { + $request = $event->getRequest(); + if (!$request->hasSession()) { return; } + $session = $request->getSession(); if ($wasStarted = $session->isStarted()) { $session->save(); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php index 22a2b71239..84ca04a680 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php @@ -123,6 +123,16 @@ class TestSessionListenerTest extends TestCase $this->assertFalse(is_subclass_of(TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford')); } + public function testDoesNotThrowIfRequestDoesNotHaveASession() + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + + $this->listener->onKernelResponse($event); + + $this->assertTrue(true); + } + private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST) { $request->setSession($this->session);