From a0f9877b3f7ac50088b289cf4c4c83bcec17fe19 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 28 Jun 2022 19:49:55 +0200 Subject: [PATCH] Drop support for Symfony `<4.4` (#643) --- .github/workflows/tests.yaml | 14 +- composer.json | 28 +-- phpstan-baseline.neon | 85 -------- .../AbstractTracingRequestListener.php | 6 +- src/EventListener/ErrorListener.php | 10 +- src/EventListener/RequestListener.php | 10 +- src/EventListener/SubRequestListener.php | 5 +- src/EventListener/TracingRequestListener.php | 10 +- .../TracingSubRequestListener.php | 5 +- src/aliases.php | 67 ------- tests/EventListener/ErrorListenerTest.php | 36 +--- tests/EventListener/MessengerListenerTest.php | 5 - tests/EventListener/RequestListenerTest.php | 188 +----------------- .../EventListener/SubRequestListenerTest.php | 33 +-- .../TracingRequestListenerTest.php | 18 +- .../TracingSubRequestListenerTest.php | 14 +- 16 files changed, 69 insertions(+), 465 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bd6cd95a..0cbd7f5c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -24,7 +24,6 @@ jobs: - '8.0' - '8.1' symfony-version: - - 3.4.* - 4.4.* - 5.* - 6.* @@ -37,14 +36,7 @@ jobs: symfony-version: 6.* - php: '7.4' symfony-version: 6.* - - php: '8.0' - symfony-version: 3.4.* - - php: '8.1' - symfony-version: 3.4.* include: - - php: '7.2' - symfony-version: 3.4.* - dependencies: lowest - php: '7.2' symfony-version: 4.4.* dependencies: lowest @@ -71,10 +63,6 @@ jobs: - name: Setup Problem Matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Remove Symfony Messenger - run: composer remove --dev symfony/messenger --no-update - if: matrix.symfony-version == '3.4.*' - - name: Update PHPUnit run: composer require --dev phpunit/phpunit ^9.3.9 --no-update if: matrix.php == '8.0' && matrix.dependencies == 'lowest' @@ -104,7 +92,7 @@ jobs: include: - php: '7.2' dependencies: lowest - symfony-version: 3.4.* + symfony-version: 4.4.* - php: '7.4' dependencies: highest - php: '8.0' diff --git a/composer.json b/composer.json index 3cea46bf..537f5239 100644 --- a/composer.json +++ b/composer.json @@ -28,14 +28,14 @@ "php-http/discovery": "^1.11", "sentry/sdk": "^3.2", "symfony/cache-contracts": "^1.1||^2.4||^3.0", - "symfony/config": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/console": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11||^6.0", + "symfony/config": "^4.4.20||^5.0.11||^6.0", + "symfony/console": "^4.4.20||^5.0.11||^6.0", + "symfony/dependency-injection": "^4.4.20||^5.0.11||^6.0", + "symfony/event-dispatcher": "^4.4.20||^5.0.11||^6.0", + "symfony/http-kernel": "^4.4.20||^5.0.11||^6.0", "symfony/polyfill-php80": "^1.22", "symfony/psr-http-message-bridge": "^1.2||^2.0", - "symfony/security-core": "^3.4.44||^4.4.20||^5.0.11||^6.0" + "symfony/security-core": "^4.4.20||^5.0.11||^6.0" }, "require-dev": { "doctrine/dbal": "^2.13||^3.0", @@ -50,17 +50,17 @@ "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.5.14||^9.3.9", - "symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/cache": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/http-client": "^3.4.44||^4.4.20||^5.0.11||^6.0", + "symfony/browser-kit": "^4.4.20||^5.0.11||^6.0", + "symfony/cache": "^4.4.20||^5.0.11||^6.0", + "symfony/dom-crawler": "^4.4.20||^5.0.11||^6.0", + "symfony/framework-bundle": "^4.4.20||^5.0.11||^6.0", + "symfony/http-client": "^4.4.20||^5.0.11||^6.0", "symfony/messenger": "^4.4.20||^5.0.11||^6.0", "symfony/monolog-bundle": "^3.4", "symfony/phpunit-bridge": "^5.2.6||^6.0", - "symfony/process": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0", - "symfony/yaml": "^3.4.44||^4.4.20||^5.0.11||^6.0", + "symfony/process": "^4.4.20||^5.0.11||^6.0", + "symfony/twig-bundle": "^4.4.20||^5.0.11||^6.0", + "symfony/yaml": "^4.4.20||^5.0.11||^6.0", "vimeo/psalm": "^4.3" }, "suggest": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 64927ea2..df52dd92 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -155,11 +155,6 @@ parameters: count: 1 path: src/EventListener/ConsoleCommandListener.php - - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" - count: 1 - path: src/EventListener/ErrorListener.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 @@ -305,101 +300,21 @@ parameters: count: 1 path: tests/End2End/TracingEnd2EndTest.php - - - message: "#^Call to method getException\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#" - count: 1 - path: tests/EventListener/ErrorListenerTest.php - - - - message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent not found\\.$#" - count: 1 - path: tests/EventListener/ErrorListenerTest.php - - - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\ErrorListener\\:\\:handleExceptionEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ExceptionEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ExceptionEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent given\\.$#" - count: 1 - path: tests/EventListener/ErrorListenerTest.php - - - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\ErrorListenerTest\\:\\:testHandleExceptionEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#" - count: 1 - path: tests/EventListener/ErrorListenerTest.php - - - - message: "#^Class Symfony\\\\Component\\\\Messenger\\\\Event\\\\WorkerMessageFailedEvent constructor invoked with 4 parameters, 3 required\\.$#" - count: 1 - path: tests/EventListener/MessengerListenerTest.php - - - - message: "#^If condition is always false\\.$#" - count: 1 - path: tests/EventListener/MessengerListenerTest.php - - message: "#^Call to function method_exists\\(\\) with \\$this\\(Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub\\) and 'setAuthenticated' will always evaluate to false\\.$#" count: 1 path: tests/EventListener/RequestListenerTest.php - - - message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#" - count: 3 - path: tests/EventListener/RequestListenerTest.php - - - - message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#" - count: 9 - path: tests/EventListener/RequestListenerTest.php - - - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent given\\.$#" - count: 1 - path: tests/EventListener/RequestListenerTest.php - - - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" - count: 1 - path: tests/EventListener/RequestListenerTest.php - - message: "#^Parameter \\#1 \\$user of method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\AbstractToken\\:\\:setUser\\(\\) expects Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface, string\\|Stringable\\|Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface given\\.$#" count: 1 path: tests/EventListener/RequestListenerTest.php - - - message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#" - count: 1 - path: tests/EventListener/RequestListenerTest.php - - - - message: "#^Parameter \\$requestEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" - count: 1 - path: tests/EventListener/RequestListenerTest.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 path: tests/EventListener/SubRequestListenerTest.php - - - message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#" - count: 2 - path: tests/EventListener/SubRequestListenerTest.php - - - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" - count: 1 - path: tests/EventListener/SubRequestListenerTest.php - - - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\SubRequestListenerTest\\:\\:isMainRequest\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" - count: 1 - path: tests/EventListener/SubRequestListenerTest.php - - - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\SubRequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" - count: 1 - path: tests/EventListener/SubRequestListenerTest.php - - message: "#^Call to an undefined method TCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface\\:\\:delete\\(\\)\\.$#" count: 2 diff --git a/src/EventListener/AbstractTracingRequestListener.php b/src/EventListener/AbstractTracingRequestListener.php index 6bab5194..022f2d1b 100644 --- a/src/EventListener/AbstractTracingRequestListener.php +++ b/src/EventListener/AbstractTracingRequestListener.php @@ -7,6 +7,7 @@ use Sentry\State\HubInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\Routing\Route; abstract class AbstractTracingRequestListener @@ -34,11 +35,10 @@ public function __construct(HubInterface $hub) * gathering information like the HTTP status code and attaching them as * tags of the span/transaction. * - * @param RequestListenerResponseEvent $event The event + * @param ResponseEvent $event The event */ - public function handleKernelResponseEvent(RequestListenerResponseEvent $event): void + public function handleKernelResponseEvent(ResponseEvent $event): void { - /** @var Response $response */ $response = $event->getResponse(); $span = $this->hub->getSpan(); diff --git a/src/EventListener/ErrorListener.php b/src/EventListener/ErrorListener.php index dc3e3776..5ebf8fdd 100644 --- a/src/EventListener/ErrorListener.php +++ b/src/EventListener/ErrorListener.php @@ -30,14 +30,10 @@ public function __construct(HubInterface $hub) /** * Handles an exception that happened while running the application. * - * @param ErrorListenerExceptionEvent $event The event + * @param ExceptionEvent $event The event */ - public function handleExceptionEvent(ErrorListenerExceptionEvent $event): void + public function handleExceptionEvent(ExceptionEvent $event): void { - if ($event instanceof ExceptionEvent) { - $this->hub->captureException($event->getThrowable()); - } else { - $this->hub->captureException($event->getException()); - } + $this->hub->captureException($event->getThrowable()); } } diff --git a/src/EventListener/RequestListener.php b/src/EventListener/RequestListener.php index 7c094ca7..2ab094d7 100644 --- a/src/EventListener/RequestListener.php +++ b/src/EventListener/RequestListener.php @@ -7,6 +7,8 @@ use Sentry\State\HubInterface; use Sentry\State\Scope; use Sentry\UserDataBag; +use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -46,9 +48,9 @@ public function __construct(HubInterface $hub, ?TokenStorageInterface $tokenStor * This method is called for each request handled by the framework and * fills the Sentry scope with information about the current user. * - * @param RequestListenerRequestEvent $event The event + * @param RequestEvent $event The event */ - public function handleKernelRequestEvent(RequestListenerRequestEvent $event): void + public function handleKernelRequestEvent(RequestEvent $event): void { if (!$this->isMainRequest($event)) { return; @@ -81,9 +83,9 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo * This method is called for each request handled by the framework and * sets the route on the current Sentry scope. * - * @param RequestListenerControllerEvent $event The event + * @param ControllerEvent $event The event */ - public function handleKernelControllerEvent(RequestListenerControllerEvent $event): void + public function handleKernelControllerEvent(ControllerEvent $event): void { if (!$this->isMainRequest($event)) { return; diff --git a/src/EventListener/SubRequestListener.php b/src/EventListener/SubRequestListener.php index c835cc31..68c26d63 100644 --- a/src/EventListener/SubRequestListener.php +++ b/src/EventListener/SubRequestListener.php @@ -6,6 +6,7 @@ use Sentry\State\HubInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * This listener ensures that a new {@see \Sentry\State\Scope} is created for @@ -34,9 +35,9 @@ public function __construct(HubInterface $hub) * This method is called for each subrequest handled by the framework and * pushes a new {@see \Sentry\State\Scope} onto the stack. * - * @param SubRequestListenerRequestEvent $event The event + * @param RequestEvent $event The event */ - public function handleKernelRequestEvent(SubRequestListenerRequestEvent $event): void + public function handleKernelRequestEvent(RequestEvent $event): void { if ($this->isMainRequest($event)) { return; diff --git a/src/EventListener/TracingRequestListener.php b/src/EventListener/TracingRequestListener.php index 3166dabf..b10cee9f 100644 --- a/src/EventListener/TracingRequestListener.php +++ b/src/EventListener/TracingRequestListener.php @@ -7,6 +7,8 @@ use Sentry\Tracing\Transaction; use Sentry\Tracing\TransactionContext; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; /** * This event listener acts on the master requests and starts a transaction @@ -20,9 +22,9 @@ final class TracingRequestListener extends AbstractTracingRequestListener * This method is called for each subrequest handled by the framework and * starts a new {@see Transaction}. * - * @param RequestListenerRequestEvent $event The event + * @param RequestEvent $event The event */ - public function handleKernelRequestEvent(RequestListenerRequestEvent $event): void + public function handleKernelRequestEvent(RequestEvent $event): void { if (!$this->isMainRequest($event)) { return; @@ -47,9 +49,9 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo * This method is called for each request handled by the framework and * ends the tracing on terminate after the client received the response. * - * @param RequestListenerTerminateEvent $event The event + * @param TerminateEvent $event The event */ - public function handleKernelTerminateEvent(RequestListenerTerminateEvent $event): void + public function handleKernelTerminateEvent(TerminateEvent $event): void { $transaction = $this->hub->getTransaction(); diff --git a/src/EventListener/TracingSubRequestListener.php b/src/EventListener/TracingSubRequestListener.php index 298a8839..b61b15b4 100644 --- a/src/EventListener/TracingSubRequestListener.php +++ b/src/EventListener/TracingSubRequestListener.php @@ -7,6 +7,7 @@ use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * This event listener acts on the sub requests and starts a child span of the @@ -18,9 +19,9 @@ final class TracingSubRequestListener extends AbstractTracingRequestListener * This method is called for each subrequest handled by the framework and * traces each by starting a new {@see Span}. * - * @param SubRequestListenerRequestEvent $event The event + * @param RequestEvent $event The event */ - public function handleKernelRequestEvent(SubRequestListenerRequestEvent $event): void + public function handleKernelRequestEvent(RequestEvent $event): void { if ($this->isMainRequest($event)) { return; diff --git a/src/aliases.php b/src/aliases.php index 6e246e43..3f81d525 100644 --- a/src/aliases.php +++ b/src/aliases.php @@ -5,12 +5,6 @@ namespace Sentry\SentryBundle; use Doctrine\DBAL\Result; -use Sentry\SentryBundle\EventListener\ErrorListenerExceptionEvent; -use Sentry\SentryBundle\EventListener\RequestListenerControllerEvent; -use Sentry\SentryBundle\EventListener\RequestListenerRequestEvent; -use Sentry\SentryBundle\EventListener\RequestListenerResponseEvent; -use Sentry\SentryBundle\EventListener\RequestListenerTerminateEvent; -use Sentry\SentryBundle\EventListener\SubRequestListenerRequestEvent; use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapter; use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapterForV2; use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapterForV3; @@ -33,69 +27,8 @@ use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\HttpClient\Response\StreamableInterface; -use Symfony\Component\HttpKernel\Event\ControllerEvent; -use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -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\ResponseEvent; -use Symfony\Component\HttpKernel\Event\TerminateEvent; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Contracts\HttpClient\ResponseInterface; -if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - if (!class_exists(ErrorListenerExceptionEvent::class, false)) { - class_alias(ExceptionEvent::class, ErrorListenerExceptionEvent::class); - } - - if (!class_exists(RequestListenerRequestEvent::class, false)) { - class_alias(RequestEvent::class, RequestListenerRequestEvent::class); - } - - if (!class_exists(RequestListenerControllerEvent::class, false)) { - class_alias(ControllerEvent::class, RequestListenerControllerEvent::class); - } - - if (!class_exists(RequestListenerResponseEvent::class, false)) { - class_alias(ResponseEvent::class, RequestListenerResponseEvent::class); - } - - if (!class_exists(RequestListenerTerminateEvent::class, false)) { - class_alias(TerminateEvent::class, RequestListenerTerminateEvent::class); - } - - if (!class_exists(SubRequestListenerRequestEvent::class, false)) { - class_alias(RequestEvent::class, SubRequestListenerRequestEvent::class); - } -} else { - if (!class_exists(ErrorListenerExceptionEvent::class, false)) { - class_alias(GetResponseForExceptionEvent::class, ErrorListenerExceptionEvent::class); - } - - if (!class_exists(RequestListenerRequestEvent::class, false)) { - class_alias(GetResponseEvent::class, RequestListenerRequestEvent::class); - } - - if (!class_exists(RequestListenerControllerEvent::class, false)) { - class_alias(FilterControllerEvent::class, RequestListenerControllerEvent::class); - } - - if (!class_exists(RequestListenerResponseEvent::class, false)) { - class_alias(FilterResponseEvent::class, RequestListenerResponseEvent::class); - } - - if (!class_exists(RequestListenerTerminateEvent::class, false)) { - class_alias(PostResponseEvent::class, RequestListenerTerminateEvent::class); - } - - if (!class_exists(SubRequestListenerRequestEvent::class, false)) { - class_alias(GetResponseEvent::class, SubRequestListenerRequestEvent::class); - } -} - if (interface_exists(AdapterInterface::class)) { if (!class_exists(DoctrineProvider::class, false) && version_compare(\PHP_VERSION, '8.0.0', '>=')) { if (!class_exists(TraceableCacheAdapter::class, false)) { diff --git a/tests/EventListener/ErrorListenerTest.php b/tests/EventListener/ErrorListenerTest.php index 163ca961..f97ff438 100644 --- a/tests/EventListener/ErrorListenerTest.php +++ b/tests/EventListener/ErrorListenerTest.php @@ -10,9 +10,7 @@ use Sentry\State\HubInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Kernel; final class ErrorListenerTest extends TestCase { @@ -33,16 +31,13 @@ protected function setUp(): void } /** - * @dataProvider handleExceptionEventForSymfonyVersionAtLeast43DataProvider - * @dataProvider handleExceptionEventForSymfonyVersionLowerThan43DataProvider - * - * @param ExceptionEvent|GetResponseForExceptionEvent $event + * @dataProvider handleExceptionEventDataProvider */ - public function testHandleExceptionEvent($event): void + public function testHandleExceptionEvent(ExceptionEvent $event): void { $this->hub->expects($this->once()) ->method('captureException') - ->with($event instanceof ExceptionEvent ? $event->getThrowable() : $event->getException()); + ->with($event->getThrowable()); $this->listener->handleExceptionEvent($event); } @@ -50,31 +45,8 @@ public function testHandleExceptionEvent($event): void /** * @return \Generator */ - public function handleExceptionEventForSymfonyVersionLowerThan43DataProvider(): \Generator + public function handleExceptionEventDataProvider(): \Generator { - if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - return; - } - - yield [ - new GetResponseForExceptionEvent( - $this->createMock(HttpKernelInterface::class), - new Request(), - HttpKernelInterface::MASTER_REQUEST, - new \Exception() - ), - ]; - } - - /** - * @return \Generator - */ - public function handleExceptionEventForSymfonyVersionAtLeast43DataProvider(): \Generator - { - if (version_compare(Kernel::VERSION, '4.3.0', '<')) { - return; - } - yield [ new ExceptionEvent( $this->createMock(HttpKernelInterface::class), diff --git a/tests/EventListener/MessengerListenerTest.php b/tests/EventListener/MessengerListenerTest.php index 04976652..af7b8462 100644 --- a/tests/EventListener/MessengerListenerTest.php +++ b/tests/EventListener/MessengerListenerTest.php @@ -9,7 +9,6 @@ use Sentry\ClientInterface; use Sentry\Event; use Sentry\SentryBundle\EventListener\MessengerListener; -use Sentry\SentryBundle\Tests\End2End\App\Kernel; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\Messenger\Envelope; @@ -194,10 +193,6 @@ public function testHandleWorkerMessageHandledEvent(): void private function getMessageFailedEvent(Envelope $envelope, string $receiverName, \Throwable $error, bool $retry): WorkerMessageFailedEvent { - if (version_compare(Kernel::VERSION, '4.4.0', '<')) { - return new WorkerMessageFailedEvent($envelope, $receiverName, $error, $retry); - } - $event = new WorkerMessageFailedEvent($envelope, $receiverName, $error); if ($retry) { diff --git a/tests/EventListener/RequestListenerTest.php b/tests/EventListener/RequestListenerTest.php index 863dddbd..372cab8a 100644 --- a/tests/EventListener/RequestListenerTest.php +++ b/tests/EventListener/RequestListenerTest.php @@ -17,8 +17,6 @@ use Sentry\UserDataBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; @@ -52,12 +50,9 @@ protected function setUp(): void } /** - * @dataProvider handleKernelRequestEventForSymfonyVersionAtLeast43DataProvider - * @dataProvider handleKernelRequestEventForSymfonyVersionLowerThan43DataProvider - * - * @param GetResponseEvent|RequestEvent $requestEvent + * @dataProvider handleKernelRequestEventDataProvider */ - public function testHandleKernelRequestEvent($requestEvent, ?ClientInterface $client, ?TokenInterface $token, ?UserDataBag $expectedUser): void + public function testHandleKernelRequestEvent(RequestEvent $requestEvent, ?ClientInterface $client, ?TokenInterface $token, ?UserDataBag $expectedUser): void { $scope = new Scope(); @@ -86,126 +81,8 @@ public function testHandleKernelRequestEvent($requestEvent, ?ClientInterface $cl /** * @return \Generator */ - public function handleKernelRequestEventForSymfonyVersionLowerThan43DataProvider(): \Generator + public function handleKernelRequestEventDataProvider(): \Generator { - if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - return; - } - - yield 'event.requestType != MASTER_REQUEST' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::SUB_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - null, - null, - ]; - - yield 'options.send_default_pii = FALSE' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => false])), - null, - null, - ]; - - yield 'token IS NULL' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - null, - UserDataBag::createFromUserIpAddress('127.0.0.1'), - ]; - - yield 'token.authenticated = FALSE' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new UnauthenticatedTokenStub(), - UserDataBag::createFromUserIpAddress('127.0.0.1'), - ]; - - yield 'token.authenticated = TRUE && token.user IS NULL' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new AuthenticatedTokenStub(null), - UserDataBag::createFromUserIpAddress('127.0.0.1'), - ]; - - yield 'token.authenticated = TRUE && token.user INSTANCEOF string' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new AuthenticatedTokenStub('foo_user'), - new UserDataBag(null, null, '127.0.0.1', 'foo_user'), - ]; - - yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new AuthenticatedTokenStub(new UserWithoutIdentifierStub()), - new UserDataBag(null, null, '127.0.0.1', 'foo_user'), - ]; - - yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method EXISTS' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new AuthenticatedTokenStub(new UserWithIdentifierStub()), - new UserDataBag(null, null, '127.0.0.1', 'foo_user'), - ]; - - yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS' => [ - new GetResponseEvent( - $this->createMock(HttpKernelInterface::class), - new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST - ), - $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), - new AuthenticatedTokenStub(new class() implements \Stringable { - public function __toString(): string - { - return 'foo_user'; - } - }), - new UserDataBag(null, null, '127.0.0.1', 'foo_user'), - ]; - } - - /** - * @return \Generator - */ - public function handleKernelRequestEventForSymfonyVersionAtLeast43DataProvider(): \Generator - { - if (version_compare(Kernel::VERSION, '4.3.0', '<')) { - return; - } - yield 'event.requestType != MASTER_REQUEST' => [ new RequestEvent( $this->createMock(HttpKernelInterface::class), @@ -325,13 +202,11 @@ public function __toString(): string } /** - * @dataProvider handleKernelControllerEventWithSymfonyVersionAtLeast43DataProvider - * @dataProvider handleKernelControllerEventWithSymfonyVersionLowerThan43DataProvider + * @dataProvider handleKernelControllerEventDataProvider * - * @param ControllerEvent|FilterControllerEvent $controllerEvent - * @param array $expectedTags + * @param array $expectedTags */ - public function testHandleKernelControllerEvent($controllerEvent, array $expectedTags): void + public function testHandleKernelControllerEvent(ControllerEvent $controllerEvent, array $expectedTags): void { $scope = new Scope(); @@ -352,12 +227,8 @@ public function testHandleKernelControllerEvent($controllerEvent, array $expecte /** * @return \Generator */ - public function handleKernelControllerEventWithSymfonyVersionAtLeast43DataProvider(): \Generator + public function handleKernelControllerEventDataProvider(): \Generator { - if (version_compare(Kernel::VERSION, '4.3.0', '<')) { - return; - } - yield 'event.requestType != MASTER_REQUEST' => [ new ControllerEvent( $this->createMock(HttpKernelInterface::class), @@ -394,51 +265,6 @@ static function () { ]; } - /** - * @return \Generator - */ - public function handleKernelControllerEventWithSymfonyVersionLowerThan43DataProvider(): \Generator - { - if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - return; - } - - yield 'event.requestType != MASTER_REQUEST' => [ - new FilterControllerEvent( - $this->createMock(HttpKernelInterface::class), - static function () { - }, - new Request([], [], ['_route' => 'homepage']), - HttpKernelInterface::SUB_REQUEST - ), - [], - ]; - - yield 'event.requestType = MASTER_REQUEST && request.attributes._route NOT EXISTS ' => [ - new FilterControllerEvent( - $this->createMock(HttpKernelInterface::class), - static function () { - }, - new Request(), - HttpKernelInterface::MASTER_REQUEST - ), - [], - ]; - - yield 'event.requestType = MASTER_REQUEST && request.attributes._route EXISTS' => [ - new FilterControllerEvent( - $this->createMock(HttpKernelInterface::class), - static function () { - }, - new Request([], [], ['_route' => 'homepage']), - HttpKernelInterface::MASTER_REQUEST - ), - [ - 'route' => 'homepage', - ], - ]; - } - private function getMockedClientWithOptions(Options $options): ClientInterface { $client = $this->createMock(ClientInterface::class); diff --git a/tests/EventListener/SubRequestListenerTest.php b/tests/EventListener/SubRequestListenerTest.php index c67dda25..c8c0b915 100644 --- a/tests/EventListener/SubRequestListenerTest.php +++ b/tests/EventListener/SubRequestListenerTest.php @@ -12,10 +12,8 @@ use Sentry\State\Scope; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Kernel; class SubRequestListenerTest extends TestCase { @@ -38,12 +36,9 @@ protected function setUp(): void } /** - * @dataProvider handleKernelRequestEventWithSymfonyVersionAtLeast43DataProvider - * @dataProvider handleKernelRequestEventWithSymfonyVersionLowerThan43DataProvider - * - * @param RequestEvent|GetResponseEvent $event + * @dataProvider handleKernelRequestEventDataProvider */ - public function testHandleKernelRequestEvent($event): void + public function testHandleKernelRequestEvent(RequestEvent $event): void { $this->hub->expects($this->isMainRequest($event) ? $this->never() : $this->once()) ->method('pushScope') @@ -55,12 +50,8 @@ public function testHandleKernelRequestEvent($event): void /** * @return \Generator */ - public function handleKernelRequestEventWithSymfonyVersionAtLeast43DataProvider(): \Generator + public function handleKernelRequestEventDataProvider(): \Generator { - if (version_compare(Kernel::VERSION, '4.3.0', '<')) { - return; - } - yield [ new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST), ]; @@ -70,24 +61,6 @@ public function handleKernelRequestEventWithSymfonyVersionAtLeast43DataProvider( ]; } - /** - * @return \Generator - */ - public function handleKernelRequestEventWithSymfonyVersionLowerThan43DataProvider(): \Generator - { - if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - return; - } - - yield [ - new GetResponseEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST), - ]; - - yield [ - new GetResponseEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::SUB_REQUEST), - ]; - } - /** * @dataProvider handleKernelFinishRequestEventDataProvider * diff --git a/tests/EventListener/TracingRequestListenerTest.php b/tests/EventListener/TracingRequestListenerTest.php index 17c8c793..cfc57c40 100644 --- a/tests/EventListener/TracingRequestListenerTest.php +++ b/tests/EventListener/TracingRequestListenerTest.php @@ -8,9 +8,6 @@ use PHPUnit\Framework\TestCase; use Sentry\ClientInterface; use Sentry\Options; -use Sentry\SentryBundle\EventListener\RequestListenerRequestEvent; -use Sentry\SentryBundle\EventListener\RequestListenerResponseEvent; -use Sentry\SentryBundle\EventListener\RequestListenerTerminateEvent; use Sentry\SentryBundle\EventListener\TracingRequestListener; use Sentry\State\HubInterface; use Sentry\Tracing\SpanId; @@ -21,6 +18,9 @@ use Symfony\Bridge\PhpUnit\ClockMock; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\Route; @@ -73,7 +73,7 @@ public function testHandleKernelRequestEvent(Options $options, Request $request, ->method('setSpan') ->with($transaction); - $this->listener->handleKernelRequestEvent(new RequestListenerRequestEvent( + $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST @@ -354,7 +354,7 @@ public function testHandleKernelRequestEventDoesNothingIfRequestTypeIsSubRequest $this->hub->expects($this->never()) ->method('startTransaction'); - $this->listener->handleKernelRequestEvent(new RequestListenerRequestEvent( + $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::SUB_REQUEST @@ -369,7 +369,7 @@ public function testHandleResponseRequestEvent(): void ->method('getSpan') ->willReturn($transaction); - $this->listener->handleKernelResponseEvent(new RequestListenerResponseEvent( + $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST, @@ -386,7 +386,7 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH ->method('getSpan') ->willReturn(null); - $this->listener->handleKernelResponseEvent(new RequestListenerResponseEvent( + $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST, @@ -405,7 +405,7 @@ public function testHandleKernelTerminateEvent(): void ->method('getTransaction') ->willReturn($transaction); - $this->listener->handleKernelTerminateEvent(new RequestListenerTerminateEvent( + $this->listener->handleKernelTerminateEvent(new TerminateEvent( $this->createMock(HttpKernelInterface::class), new Request(), new Response() @@ -420,7 +420,7 @@ public function testHandleKernelTerminateEventDoesNothingIfNoTransactionIsSetOnH ->method('getTransaction') ->willReturn(null); - $this->listener->handleKernelTerminateEvent(new RequestListenerTerminateEvent( + $this->listener->handleKernelTerminateEvent(new TerminateEvent( $this->createMock(HttpKernelInterface::class), new Request(), new Response() diff --git a/tests/EventListener/TracingSubRequestListenerTest.php b/tests/EventListener/TracingSubRequestListenerTest.php index eb77f58a..9503e2a3 100644 --- a/tests/EventListener/TracingSubRequestListenerTest.php +++ b/tests/EventListener/TracingSubRequestListenerTest.php @@ -6,8 +6,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Sentry\SentryBundle\EventListener\RequestListenerResponseEvent; -use Sentry\SentryBundle\EventListener\SubRequestListenerRequestEvent; use Sentry\SentryBundle\EventListener\TracingSubRequestListener; use Sentry\State\HubInterface; use Sentry\Tracing\Span; @@ -15,6 +13,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; final class TracingSubRequestListenerTest extends TestCase @@ -57,7 +57,7 @@ public function testHandleKernelRequestEvent(Request $request, Span $expectedSpa })) ->willReturnSelf(); - $this->listener->handleKernelRequestEvent(new SubRequestListenerRequestEvent( + $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::SUB_REQUEST @@ -143,7 +143,7 @@ public function testHandleKernelRequestEventDoesNothingIfRequestTypeIsMasterRequ $this->hub->expects($this->never()) ->method('getSpan'); - $this->listener->handleKernelRequestEvent(new SubRequestListenerRequestEvent( + $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST @@ -156,7 +156,7 @@ public function testHandleKernelRequestEventDoesNothingIfNoSpanIsSetOnHub(): voi ->method('getSpan') ->willReturn(null); - $this->listener->handleKernelRequestEvent(new SubRequestListenerRequestEvent( + $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::SUB_REQUEST @@ -216,7 +216,7 @@ public function testHandleResponseRequestEvent(): void ->method('getSpan') ->willReturn($span); - $this->listener->handleKernelResponseEvent(new RequestListenerResponseEvent( + $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::SUB_REQUEST, @@ -233,7 +233,7 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH ->method('getSpan') ->willReturn(null); - $this->listener->handleKernelResponseEvent(new RequestListenerResponseEvent( + $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::SUB_REQUEST,