Skip to content

Add SessionListener::onFinishRequest method to be inline with Symfony 3.4.12 #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions EventListener/SessionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;

Expand Down Expand Up @@ -78,6 +79,13 @@ public function onKernelResponse(FilterResponseEvent $event)
// noop, see class description
}

public function onFinishRequest(FinishRequestEvent $event)
{
if (method_exists($this->inner, 'onFinishRequest')) {
$this->inner->onFinishRequest($event);
}
}

public static function getSubscribedEvents()
{
return BaseSessionListener::getSubscribedEvents();
Expand Down
26 changes: 26 additions & 0 deletions Tests/Unit/EventListener/SessionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ public function testOnKernelRequestRemainsUntouched()
$listener->onKernelRequest($event);
}

public function testOnFinishRequestRemainsUntouched()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should be skipped if the method does not exist in the core session listener. See https://travis-ci.org/FriendsOfSymfony/FOSHttpCacheBundle/jobs/396800434

Copy link
Contributor Author

@emodric emodric Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Toflar Done, however, PHP 5.4 and 5.6 builds still fail due to OOM errors.

{
if (!method_exists('Symfony\Component\HttpKernel\EventListener\SessionListener', 'onFinishRequest')) {
$this->markTestSkipped('Method onFinishRequest does not exist on Symfony\Component\HttpKernel\EventListener\SessionListener');
}

$event = $this
->getMockBuilder('Symfony\Component\HttpKernel\Event\FinishRequestEvent')
->disableOriginalConstructor()
->getMock();

$inner = $this
->getMockBuilder('Symfony\Component\HttpKernel\EventListener\SessionListener')
->disableOriginalConstructor()
->getMock();

$inner
->expects($this->once())
->method('onFinishRequest')
->with($event)
;

$listener = $this->getListener($inner);
$listener->onFinishRequest($event);
}

/**
* @dataProvider onKernelResponseProvider
*/
Expand Down