Skip to content

Commit

Permalink
Make compatibility for Symfony >= 4.4 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecourtial authored Jul 6, 2020
1 parent cfc16b2 commit b4b9ace
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
}
},
"require": {
"symfony/dependency-injection": "~3.0",
"symfony/symfony": ">=3.0 <4.3",
"symfony/symfony": ">=4.4",
"wizaplace/elastic-apm-wrapper": "^0.4.2"
},
"require-dev": {
Expand Down
18 changes: 9 additions & 9 deletions src/ElasticApmSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Wizacha\ElasticApmBundle;

use PhilKra\Exception\Transaction\DuplicateTransactionNameException;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class ElasticApmSubscriber extends ElasticApmAbstractSubscriber
Expand All @@ -29,24 +29,24 @@ public static function getSubscribedEvents()
/**
* @throws DuplicateTransactionNameException
*/
public function onKernelRequest(GetResponseEvent $kernelEvent)
public function onKernelRequest(RequestEvent $requestEvent)
{
if (true === $kernelEvent->isMasterRequest() && null === $this->transaction) {
if (true === $requestEvent->isMasterRequest() && null === $this->transaction) {
$this->transaction = $this->agentService
->startTransaction(
sprintf(
'%s %s (%s)',
$kernelEvent->getRequest()->getMethod(),
$kernelEvent->getRequest()->get('_controller'),
$kernelEvent->getRequest()->get('_route')
$requestEvent->getRequest()->getMethod(),
$requestEvent->getRequest()->get('_controller'),
$requestEvent->getRequest()->get('_route')
)
)
->getTransaction();
}
}

public function onKernelException(GetResponseForExceptionEvent $kernelEvent)
public function onKernelException(ExceptionEvent $event)
{
$this->agentService->error($kernelEvent->getException());
$this->agentService->error($event->getThrowable());
}
}
14 changes: 7 additions & 7 deletions tests/ElasticApmSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\KernelInterface;
use Wizacha\ElasticApm\Service\AgentService;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function testEventSubscription(): void
public function testOnExceptionNewError(): void
{
$elasticApmSubscriber = new ElasticApmSubscriber($this->agentService);
$exception = new GetResponseForExceptionEvent($this->kernel, new Request(), 1, new \Exception('Ceci est une exception'));
$exception = new ExceptionEvent($this->kernel, new Request(), 1, new \Exception('Ceci est une exception'));

$this->agentService
->expects($this->once())
Expand All @@ -61,7 +61,7 @@ public function testOnExceptionNewError(): void
public function testOnRequestNewTransaction(): void
{
$elasticApmSubscriber = new ElasticApmSubscriber($this->agentService);
$event = new GetResponseEvent($this->kernel, new Request(), 1);
$event = new RequestEvent($this->kernel, new Request(), 1);

$this->agentService
->expects($this->once())
Expand All @@ -80,11 +80,11 @@ public function testOnTerminateStopTransaction(): void
->will($this->returnValue(new Transaction('New transaction', [])));

$elasticApmSubscriber = new ElasticApmSubscriber($this->agentService);
$event = new GetResponseEvent($this->kernel, new Request(), 1);
$event = new RequestEvent($this->kernel, new Request(), 1);

$elasticApmSubscriber->onKernelRequest($event);

new PostResponseEvent($this->kernel, new Request(), new Response());
new TerminateEvent($this->kernel, new Request(), new Response());

$this->agentService
->expects($this->once())
Expand Down

0 comments on commit b4b9ace

Please sign in to comment.