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
-------

0ecaefe179 [HttpKernel] fix deprecation in AbstractTestSessionListener
This commit is contained in:
Nicolas Grekas 2018-05-25 16:30:50 +02:00
commit 7d23ac529f
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);