From a974410b63a72ab9c572151614b41ee5b710b6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 16 Dec 2019 09:59:07 +0100 Subject: [PATCH] Fix wrong event typehinted in RequestListener --- Listener/RequestListener.php | 6 +++--- Tests/Listener/RequestListenerTest.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Listener/RequestListener.php b/Listener/RequestListener.php index 0487720..841d5ad 100644 --- a/Listener/RequestListener.php +++ b/Listener/RequestListener.php @@ -18,7 +18,7 @@ use Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -116,8 +116,8 @@ private function isEventValid(KernelRequestEvent $event): bool } } -if (\class_exists(ResponseEvent::class)) { - \class_alias(ResponseEvent::class, KernelRequestEvent::class); +if (\class_exists(RequestEvent::class)) { + \class_alias(RequestEvent::class, KernelRequestEvent::class); } else { \class_alias(GetResponseEvent::class, KernelRequestEvent::class); } diff --git a/Tests/Listener/RequestListenerTest.php b/Tests/Listener/RequestListenerTest.php index 5518e95..e268671 100644 --- a/Tests/Listener/RequestListenerTest.php +++ b/Tests/Listener/RequestListenerTest.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; class RequestListenerTest extends TestCase @@ -35,7 +35,7 @@ public function testSubRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); @@ -54,7 +54,7 @@ public function testMasterRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); @@ -71,7 +71,7 @@ public function testPathIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], [], [], [], ['REQUEST_URI' => '/ignored_path']); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], ['/ignored_path'], $namingStrategy); @@ -88,7 +88,7 @@ public function testRouteIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], ['_route' => 'ignored_route']); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, ['ignored_route'], [], $namingStrategy); @@ -104,7 +104,7 @@ public function testSymfonyCacheEnabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, true); @@ -120,7 +120,7 @@ public function testSymfonyCacheDisabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = \class_exists(ResponseEvent::class) ? ResponseEvent::class : GetResponseEvent::class; + $eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, false);