diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 60067434..c488affa 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -32,6 +32,7 @@ jobs: - 4.4.* - 5.* - 6.* + - 7.* dependencies: - highest exclude: @@ -41,6 +42,16 @@ jobs: symfony-version: 6.* - php: '7.4' symfony-version: 6.* + - php: '7.2' + symfony-version: 7.* + - php: '7.3' + symfony-version: 7.* + - php: '7.4' + symfony-version: 7.* + - php: '8.0' + symfony-version: 7.* + - php: '8.1' + symfony-version: 7.* include: - php: '7.2' symfony-version: 4.4.* @@ -51,6 +62,9 @@ jobs: - php: '8.0' symfony-version: 6.* dependencies: lowest + - php: '8.2' + symfony-version: 7.* + dependencies: lowest steps: - name: Checkout diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7136604b..5906a68d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -14,10 +14,14 @@ 'imports_order' => ['class', 'function', 'const'], ], 'declare_strict_types' => true, + 'get_class_to_class_keyword' => false, 'random_api_migration' => true, 'yoda_style' => true, 'self_accessor' => false, + 'nullable_type_declaration_for_default_null_value' => false, + 'no_null_property_initialization' => false, 'phpdoc_no_useless_inheritdoc' => false, + 'no_superfluous_phpdoc_tags' => false, 'phpdoc_to_comment' => false, 'phpdoc_align' => [ 'tags' => ['param', 'return', 'throws', 'type', 'var'], diff --git a/composer.json b/composer.json index 17d3a788..4af78805 100644 --- a/composer.json +++ b/composer.json @@ -27,40 +27,41 @@ "php": "^7.2||^8.0", "guzzlehttp/psr7": "^1.7 || ^2.0", "jean85/pretty-package-versions": "^1.5 || ^2.0", - "sentry/sdk": "^3.4", - "sentry/sentry": "^3.20.1", + "sentry/sdk": "^3.6", + "sentry/sentry": "^3.22.1", "symfony/cache-contracts": "^1.1||^2.4||^3.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/config": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/dependency-injection": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/event-dispatcher": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/http-kernel": "^4.4.20||^5.0.11||^6.0||^7.0", "symfony/polyfill-php80": "^1.22", - "symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4", - "symfony/security-core": "^4.4.20||^5.0.11||^6.0", - "symfony/security-http": "^4.4.20||^5.0.11||^6.0" + "symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4||^7.0", + "symfony/security-core": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/security-http": "^4.4.20||^5.0.11||^6.0||^7.0" }, "require-dev": { "doctrine/dbal": "^2.13||^3.0", "doctrine/doctrine-bundle": "^1.12||^2.5", - "friendsofphp/php-cs-fixer": "^2.19||<=3.16.0", + "friendsofphp/php-cs-fixer": "^2.19||^3.40", + "masterminds/html5": "^2.8", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.3", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.5.14||^9.3.9", - "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/browser-kit": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/cache": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/dom-crawler": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/framework-bundle": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/http-client": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/messenger": "^4.4.20||^5.0.11||^6.0||^7.0", "symfony/monolog-bundle": "^3.4", - "symfony/phpunit-bridge": "^5.2.6||^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" + "symfony/phpunit-bridge": "^5.2.6||^6.0||^7.0", + "symfony/process": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/twig-bundle": "^4.4.20||^5.0.11||^6.0||^7.0", + "symfony/yaml": "^4.4.20||^5.0.11||^6.0||^7.0", + "vimeo/psalm": "^4.3||^5.16.0" }, "suggest": { "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler.", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 13f319ec..15552cc2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -330,6 +330,16 @@ parameters: count: 1 path: tests/End2End/TracingEnd2EndTest.php + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 1 + path: tests/EventListener/ErrorListenerTest.php + + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 2 + path: tests/EventListener/LoginListenerTest.php + - message: "#^Call to function method_exists\\(\\) with \\$this\\(Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub\\) and 'setAuthenticated' will always evaluate to false\\.$#" count: 1 @@ -360,11 +370,31 @@ parameters: count: 1 path: tests/EventListener/LoginListenerTest.php + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 6 + path: tests/EventListener/RequestListenerTest.php + + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 2 + path: tests/EventListener/SubRequestListenerTest.php + - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 path: tests/EventListener/SubRequestListenerTest.php + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 3 + path: tests/EventListener/TracingRequestListenerTest.php + + - + message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#" + count: 2 + path: tests/EventListener/TracingSubRequestListenerTest.php + - message: "#^Call to an undefined method TCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface\\:\\:delete\\(\\)\\.$#" count: 2 diff --git a/src/EventListener/MessengerListener.php b/src/EventListener/MessengerListener.php index 2c139ca6..b66b962c 100644 --- a/src/EventListener/MessengerListener.php +++ b/src/EventListener/MessengerListener.php @@ -13,6 +13,7 @@ use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException; use Symfony\Component\Messenger\Exception\HandlerFailedException; +use Symfony\Component\Messenger\Exception\WrappedExceptionsInterface; use Symfony\Component\Messenger\Stamp\BusNameStamp; final class MessengerListener @@ -94,9 +95,11 @@ public function handleWorkerMessageHandledEvent(WorkerMessageHandledEvent $event */ private function captureException(\Throwable $exception, bool $willRetry): void { - if ($exception instanceof HandlerFailedException) { + if ($exception instanceof WrappedExceptionsInterface) { + $exception = $exception->getWrappedExceptions(); + } elseif ($exception instanceof HandlerFailedException && method_exists($exception, 'getNestedExceptions')) { $exception = $exception->getNestedExceptions(); - } elseif ($exception instanceof DelayedMessageHandlingException) { + } elseif ($exception instanceof DelayedMessageHandlingException && method_exists($exception, 'getExceptions')) { $exception = $exception->getExceptions(); } diff --git a/src/Tracing/HttpClient/AbstractTraceableHttpClient.php b/src/Tracing/HttpClient/AbstractTraceableHttpClient.php index fb5e922b..4ee8f77a 100644 --- a/src/Tracing/HttpClient/AbstractTraceableHttpClient.php +++ b/src/Tracing/HttpClient/AbstractTraceableHttpClient.php @@ -138,11 +138,11 @@ private static function shouldAttachTracingHeaders(?ClientInterface $client, Uri // Check if the request destination is allow listed in the trace_propagation_targets option. if ( - null !== $sdkOptions->getTracePropagationTargets() && + null !== $sdkOptions->getTracePropagationTargets() // Due to BC, we treat an empty array (the default) as all hosts are allow listed - ( - [] === $sdkOptions->getTracePropagationTargets() || - \in_array($uri->getHost(), $sdkOptions->getTracePropagationTargets()) + && ( + [] === $sdkOptions->getTracePropagationTargets() + || \in_array($uri->getHost(), $sdkOptions->getTracePropagationTargets()) ) ) { return true; diff --git a/tests/End2End/App/Messenger/FooMessageHandler.php b/tests/End2End/App/Messenger/FooMessageHandler.php index a2f47549..5641175d 100644 --- a/tests/End2End/App/Messenger/FooMessageHandler.php +++ b/tests/End2End/App/Messenger/FooMessageHandler.php @@ -5,9 +5,8 @@ namespace Sentry\SentryBundle\Tests\End2End\App\Messenger; use Symfony\Component\Messenger\Exception\UnrecoverableExceptionInterface; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; -class FooMessageHandler implements MessageHandlerInterface +class FooMessageHandler { public function __invoke(FooMessage $message): void { diff --git a/tests/End2End/App/messenger.yml b/tests/End2End/App/messenger.yml index 5430583e..c729467d 100644 --- a/tests/End2End/App/messenger.yml +++ b/tests/End2End/App/messenger.yml @@ -7,6 +7,8 @@ services: Sentry\SentryBundle\Tests\End2End\App\Messenger\FooMessageHandler: class: \Sentry\SentryBundle\Tests\End2End\App\Messenger\FooMessageHandler + tags: + - { name: messenger.message_handler } Sentry\SentryBundle\Tests\End2End\App\Controller\MessengerController: autowire: true diff --git a/tests/End2End/End2EndTest.php b/tests/End2End/End2EndTest.php index 3ec26438..7eef4ffd 100644 --- a/tests/End2End/End2EndTest.php +++ b/tests/End2End/End2EndTest.php @@ -198,8 +198,7 @@ public function testNotice(): void public function testCommand(): void { - self::bootKernel(); - $application = new Application(self::$kernel); + $application = new Application(self::bootKernel()); try { $application->doRun(new ArgvInput(['bin/console', 'main-command', '--option1', '--option2=foo', 'bar']), new NullOutput()); diff --git a/tests/EventListener/ErrorListenerTest.php b/tests/EventListener/ErrorListenerTest.php index 602f1d80..ec732c02 100644 --- a/tests/EventListener/ErrorListenerTest.php +++ b/tests/EventListener/ErrorListenerTest.php @@ -66,7 +66,7 @@ public function handleExceptionEventDataProvider(): \Generator new ExceptionEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST, + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST, new \Exception() ), ]; diff --git a/tests/EventListener/LoginListenerTest.php b/tests/EventListener/LoginListenerTest.php index 44c1838b..8092cc15 100644 --- a/tests/EventListener/LoginListenerTest.php +++ b/tests/EventListener/LoginListenerTest.php @@ -88,7 +88,7 @@ public function testHandleKernelRequestEvent(TokenInterface $token, ?UserDataBag $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST )); $event = $scope->applyToEvent(Event::createEvent()); @@ -273,7 +273,7 @@ public function testHandleKernelRequestEventDoesNothingIfTokenIsNotSet(): void $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST )); } diff --git a/tests/EventListener/RequestListenerTest.php b/tests/EventListener/RequestListenerTest.php index 440db6e7..5532df9d 100644 --- a/tests/EventListener/RequestListenerTest.php +++ b/tests/EventListener/RequestListenerTest.php @@ -82,7 +82,7 @@ public function handleKernelRequestEventDataProvider(): \Generator new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), $this->getMockedClientWithOptions(new Options(['send_default_pii' => false])), new UserDataBag(), @@ -93,7 +93,7 @@ public function handleKernelRequestEventDataProvider(): \Generator new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), new UserDataBag(), @@ -104,7 +104,7 @@ public function handleKernelRequestEventDataProvider(): \Generator new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), new UserDataBag('foo_user'), @@ -115,7 +115,7 @@ public function handleKernelRequestEventDataProvider(): \Generator new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), $this->getMockedClientWithOptions(new Options(['send_default_pii' => true])), new UserDataBag('foo_user', null, '::1'), @@ -168,7 +168,7 @@ static function () { static function () { }, new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), [], ]; @@ -179,7 +179,7 @@ static function () { static function () { }, new Request([], [], ['_route' => 'homepage']), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ), [ 'route' => 'homepage', diff --git a/tests/EventListener/SubRequestListenerTest.php b/tests/EventListener/SubRequestListenerTest.php index c8c0b915..3b5b63a4 100644 --- a/tests/EventListener/SubRequestListenerTest.php +++ b/tests/EventListener/SubRequestListenerTest.php @@ -53,7 +53,7 @@ public function testHandleKernelRequestEvent(RequestEvent $event): void public function handleKernelRequestEventDataProvider(): \Generator { yield [ - new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST), + new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST), ]; yield [ @@ -80,7 +80,7 @@ public function testHandleKernelFinishRequestEvent($event): void public function handleKernelFinishRequestEventDataProvider(): \Generator { yield [ - new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST), + new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST), ]; yield [ diff --git a/tests/EventListener/TracingRequestListenerTest.php b/tests/EventListener/TracingRequestListenerTest.php index 1fb74bae..739d1e11 100644 --- a/tests/EventListener/TracingRequestListenerTest.php +++ b/tests/EventListener/TracingRequestListenerTest.php @@ -78,7 +78,7 @@ public function testHandleKernelRequestEvent(Options $options, Request $request, $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), $request, - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST )); } @@ -427,7 +427,7 @@ public function testHandleResponseRequestEvent(): void $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST, + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST, new Response() )); @@ -444,7 +444,7 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH $this->listener->handleKernelResponseEvent(new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST, + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST, new Response() )); } diff --git a/tests/EventListener/TracingSubRequestListenerTest.php b/tests/EventListener/TracingSubRequestListenerTest.php index ef9da8d1..614dfc1c 100644 --- a/tests/EventListener/TracingSubRequestListenerTest.php +++ b/tests/EventListener/TracingSubRequestListenerTest.php @@ -146,7 +146,7 @@ public function testHandleKernelRequestEventDoesNothingIfRequestTypeIsMasterRequ $this->listener->handleKernelRequestEvent(new RequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST )); } @@ -191,7 +191,7 @@ public function testHandleKernelFinishRequestEventDoesNothingIfRequestTypeIsMast $this->listener->handleKernelFinishRequestEvent(new FinishRequestEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST + \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST )); }