Skip to content

Commit

Permalink
Merge pull request #244 from jderusse/fix-event
Browse files Browse the repository at this point in the history
Fix wrong event typehinted in RequestListener
  • Loading branch information
jderusse authored Dec 16, 2019
2 parents b2a7a50 + a974410 commit c9de524
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Listener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
14 changes: 7 additions & 7 deletions Tests/Listener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c9de524

Please sign in to comment.