Skip to content

Commit

Permalink
Add support for Symfony 7 (#761)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Arlandini <[email protected]>
Co-authored-by: Michael Hoffmann <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2023
1 parent 76b46d2 commit 7fec186
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 48 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- 4.4.*
- 5.*
- 6.*
- 7.*
dependencies:
- highest
exclude:
Expand All @@ -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.*
Expand All @@ -51,6 +62,9 @@ jobs:
- php: '8.0'
symfony-version: 6.*
dependencies: lowest
- php: '8.2'
symfony-version: 7.*
dependencies: lowest

steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
45 changes: 23 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
30 changes: 30 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/EventListener/MessengerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Tracing/HttpClient/AbstractTraceableHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tests/End2End/App/Messenger/FooMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions tests/End2End/App/messenger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/End2End/End2EndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/EventListener/ErrorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
),
];
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/LoginListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
));
}

Expand Down
12 changes: 6 additions & 6 deletions tests/EventListener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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'),
Expand All @@ -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'),
Expand Down Expand Up @@ -168,7 +168,7 @@ static function () {
static function () {
},
new Request(),
HttpKernelInterface::MASTER_REQUEST
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
),
[],
];
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/SubRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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 [
Expand Down
6 changes: 3 additions & 3 deletions tests/EventListener/TracingRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}

Expand Down Expand Up @@ -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()
));

Expand All @@ -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()
));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/TracingSubRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}

Expand Down Expand Up @@ -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
));
}

Expand Down

0 comments on commit 7fec186

Please sign in to comment.