Skip to content

Commit

Permalink
bug #27350 [HttpKernel] fix deprecation in AbstractTestSessionListene…
Browse files Browse the repository at this point in the history
…r (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
  • Loading branch information
nicolas-grekas committed May 25, 2018
2 parents af62eac + 0ecaefe commit 7d23ac5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -61,10 +61,12 @@ public function onKernelResponse(FilterResponseEvent $event)
return;
}

if (!$session = $event->getRequest()->getSession()) {
$request = $event->getRequest();
if (!$request->hasSession()) {
return;
}

$session = $request->getSession();
if ($wasStarted = $session->isStarted()) {
$session->save();
}
Expand Down
Expand Up @@ -123,6 +123,16 @@ public function testDoesNotImplementServiceSubscriberInterface()
$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);
Expand Down

0 comments on commit 7d23ac5

Please sign in to comment.