[HttpKernel] fix deprecation in AbstractTestSessionListener

This commit is contained in:
Alessandro Chitolina 2018-05-23 10:10:33 +02:00
parent 7fb7cf26ad
commit 0ecaefe179
No known key found for this signature in database
GPG Key ID: 245FF08D9662DB42
2 changed files with 13 additions and 1 deletions

View File

@ -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();
}

View File

@ -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);