Skip to content

Commit

Permalink
Merge pull request #472 from FriendsOfSymfony/emodric-sf3412_fix
Browse files Browse the repository at this point in the history
Add SessionListener::onFinishRequest method to work with Symfony 3.4.12
  • Loading branch information
dbu committed Jun 29, 2018
2 parents c9d5a3b + 862ac02 commit c5798e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.3.16
------

* Adjust session_listener to work with Symfony 3.4.12 (https://github.com/symfony/symfony/pull/27467).

1.3.15
------

Expand Down
7 changes: 7 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,12 @@ public function onKernelResponse(FilterResponseEvent $event)
// noop, see class description
}

public function onFinishRequest(FinishRequestEvent $event)
{
// this hook has been added in symfony 3.4.12 - older versions of the listener do not register for it
$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()
{
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

0 comments on commit c5798e9

Please sign in to comment.