diff --git a/src/bundle/Core/EventListener/SessionInitByPostListener.php b/src/bundle/Core/EventListener/SessionInitByPostListener.php index 1c2df959af..f4f9e92a08 100644 --- a/src/bundle/Core/EventListener/SessionInitByPostListener.php +++ b/src/bundle/Core/EventListener/SessionInitByPostListener.php @@ -27,9 +27,12 @@ public static function getSubscribedEvents() public function onSiteAccessMatch(PostSiteAccessMatchEvent $event) { $request = $event->getRequest(); - $session = $request->getSession(); + $session = null; + if ($request->hasSession()) { + $session = $request->getSession(); + } - if (!$session || $event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { + if (null === $session || $event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { return; } diff --git a/tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php b/tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php index cffa62b597..764624af71 100644 --- a/tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php +++ b/tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php @@ -117,6 +117,14 @@ public function testOnSiteAccessMatchNewSessionName() $this->listener->onSiteAccessMatch($event); } + + public function testOnSiteAccessMatchNoSession(): void + { + $request = new Request(); + + $event = new PostSiteAccessMatchEvent(new SiteAccess('test'), $request, HttpKernelInterface::MAIN_REQUEST); + $this->listener->onSiteAccessMatch($event); + } } class_alias(SessionInitByPostListenerTest::class, 'eZ\Bundle\EzPublishCoreBundle\Tests\EventListener\SessionInitByPostListenerTest');