Skip to content

Commit 7fec186

Browse files
Jean85ste93crycleptric
authored
Add support for Symfony 7 (#761)
Co-authored-by: Stefano Arlandini <[email protected]> Co-authored-by: Michael Hoffmann <[email protected]>
1 parent 76b46d2 commit 7fec186

15 files changed

+100
-48
lines changed

.github/workflows/tests.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- 4.4.*
3333
- 5.*
3434
- 6.*
35+
- 7.*
3536
dependencies:
3637
- highest
3738
exclude:
@@ -41,6 +42,16 @@ jobs:
4142
symfony-version: 6.*
4243
- php: '7.4'
4344
symfony-version: 6.*
45+
- php: '7.2'
46+
symfony-version: 7.*
47+
- php: '7.3'
48+
symfony-version: 7.*
49+
- php: '7.4'
50+
symfony-version: 7.*
51+
- php: '8.0'
52+
symfony-version: 7.*
53+
- php: '8.1'
54+
symfony-version: 7.*
4455
include:
4556
- php: '7.2'
4657
symfony-version: 4.4.*
@@ -51,6 +62,9 @@ jobs:
5162
- php: '8.0'
5263
symfony-version: 6.*
5364
dependencies: lowest
65+
- php: '8.2'
66+
symfony-version: 7.*
67+
dependencies: lowest
5468

5569
steps:
5670
- name: Checkout

.php-cs-fixer.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
'imports_order' => ['class', 'function', 'const'],
1515
],
1616
'declare_strict_types' => true,
17+
'get_class_to_class_keyword' => false,
1718
'random_api_migration' => true,
1819
'yoda_style' => true,
1920
'self_accessor' => false,
21+
'nullable_type_declaration_for_default_null_value' => false,
22+
'no_null_property_initialization' => false,
2023
'phpdoc_no_useless_inheritdoc' => false,
24+
'no_superfluous_phpdoc_tags' => false,
2125
'phpdoc_to_comment' => false,
2226
'phpdoc_align' => [
2327
'tags' => ['param', 'return', 'throws', 'type', 'var'],

composer.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,41 @@
2727
"php": "^7.2||^8.0",
2828
"guzzlehttp/psr7": "^1.7 || ^2.0",
2929
"jean85/pretty-package-versions": "^1.5 || ^2.0",
30-
"sentry/sdk": "^3.4",
31-
"sentry/sentry": "^3.20.1",
30+
"sentry/sdk": "^3.6",
31+
"sentry/sentry": "^3.22.1",
3232
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
33-
"symfony/config": "^4.4.20||^5.0.11||^6.0",
34-
"symfony/console": "^4.4.20||^5.0.11||^6.0",
35-
"symfony/dependency-injection": "^4.4.20||^5.0.11||^6.0",
36-
"symfony/event-dispatcher": "^4.4.20||^5.0.11||^6.0",
37-
"symfony/http-kernel": "^4.4.20||^5.0.11||^6.0",
33+
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0",
34+
"symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0",
35+
"symfony/dependency-injection": "^4.4.20||^5.0.11||^6.0||^7.0",
36+
"symfony/event-dispatcher": "^4.4.20||^5.0.11||^6.0||^7.0",
37+
"symfony/http-kernel": "^4.4.20||^5.0.11||^6.0||^7.0",
3838
"symfony/polyfill-php80": "^1.22",
39-
"symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4",
40-
"symfony/security-core": "^4.4.20||^5.0.11||^6.0",
41-
"symfony/security-http": "^4.4.20||^5.0.11||^6.0"
39+
"symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4||^7.0",
40+
"symfony/security-core": "^4.4.20||^5.0.11||^6.0||^7.0",
41+
"symfony/security-http": "^4.4.20||^5.0.11||^6.0||^7.0"
4242
},
4343
"require-dev": {
4444
"doctrine/dbal": "^2.13||^3.0",
4545
"doctrine/doctrine-bundle": "^1.12||^2.5",
46-
"friendsofphp/php-cs-fixer": "^2.19||<=3.16.0",
46+
"friendsofphp/php-cs-fixer": "^2.19||^3.40",
47+
"masterminds/html5": "^2.8",
4748
"phpstan/extension-installer": "^1.0",
4849
"phpstan/phpstan": "^1.3",
4950
"phpstan/phpstan-phpunit": "^1.0",
5051
"phpstan/phpstan-symfony": "^1.0",
5152
"phpunit/phpunit": "^8.5.14||^9.3.9",
52-
"symfony/browser-kit": "^4.4.20||^5.0.11||^6.0",
53-
"symfony/cache": "^4.4.20||^5.0.11||^6.0",
54-
"symfony/dom-crawler": "^4.4.20||^5.0.11||^6.0",
55-
"symfony/framework-bundle": "^4.4.20||^5.0.11||^6.0",
56-
"symfony/http-client": "^4.4.20||^5.0.11||^6.0",
57-
"symfony/messenger": "^4.4.20||^5.0.11||^6.0",
53+
"symfony/browser-kit": "^4.4.20||^5.0.11||^6.0||^7.0",
54+
"symfony/cache": "^4.4.20||^5.0.11||^6.0||^7.0",
55+
"symfony/dom-crawler": "^4.4.20||^5.0.11||^6.0||^7.0",
56+
"symfony/framework-bundle": "^4.4.20||^5.0.11||^6.0||^7.0",
57+
"symfony/http-client": "^4.4.20||^5.0.11||^6.0||^7.0",
58+
"symfony/messenger": "^4.4.20||^5.0.11||^6.0||^7.0",
5859
"symfony/monolog-bundle": "^3.4",
59-
"symfony/phpunit-bridge": "^5.2.6||^6.0",
60-
"symfony/process": "^4.4.20||^5.0.11||^6.0",
61-
"symfony/twig-bundle": "^4.4.20||^5.0.11||^6.0",
62-
"symfony/yaml": "^4.4.20||^5.0.11||^6.0",
63-
"vimeo/psalm": "^4.3"
60+
"symfony/phpunit-bridge": "^5.2.6||^6.0||^7.0",
61+
"symfony/process": "^4.4.20||^5.0.11||^6.0||^7.0",
62+
"symfony/twig-bundle": "^4.4.20||^5.0.11||^6.0||^7.0",
63+
"symfony/yaml": "^4.4.20||^5.0.11||^6.0||^7.0",
64+
"vimeo/psalm": "^4.3||^5.16.0"
6465
},
6566
"suggest": {
6667
"monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler.",

phpstan-baseline.neon

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ parameters:
330330
count: 1
331331
path: tests/End2End/TracingEnd2EndTest.php
332332

333+
-
334+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
335+
count: 1
336+
path: tests/EventListener/ErrorListenerTest.php
337+
338+
-
339+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
340+
count: 2
341+
path: tests/EventListener/LoginListenerTest.php
342+
333343
-
334344
message: "#^Call to function method_exists\\(\\) with \\$this\\(Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub\\) and 'setAuthenticated' will always evaluate to false\\.$#"
335345
count: 1
@@ -360,11 +370,31 @@ parameters:
360370
count: 1
361371
path: tests/EventListener/LoginListenerTest.php
362372

373+
-
374+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
375+
count: 6
376+
path: tests/EventListener/RequestListenerTest.php
377+
378+
-
379+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
380+
count: 2
381+
path: tests/EventListener/SubRequestListenerTest.php
382+
363383
-
364384
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
365385
count: 1
366386
path: tests/EventListener/SubRequestListenerTest.php
367387

388+
-
389+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
390+
count: 3
391+
path: tests/EventListener/TracingRequestListenerTest.php
392+
393+
-
394+
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
395+
count: 2
396+
path: tests/EventListener/TracingSubRequestListenerTest.php
397+
368398
-
369399
message: "#^Call to an undefined method TCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface\\:\\:delete\\(\\)\\.$#"
370400
count: 2

src/EventListener/MessengerListener.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
1414
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
1515
use Symfony\Component\Messenger\Exception\HandlerFailedException;
16+
use Symfony\Component\Messenger\Exception\WrappedExceptionsInterface;
1617
use Symfony\Component\Messenger\Stamp\BusNameStamp;
1718

1819
final class MessengerListener
@@ -94,9 +95,11 @@ public function handleWorkerMessageHandledEvent(WorkerMessageHandledEvent $event
9495
*/
9596
private function captureException(\Throwable $exception, bool $willRetry): void
9697
{
97-
if ($exception instanceof HandlerFailedException) {
98+
if ($exception instanceof WrappedExceptionsInterface) {
99+
$exception = $exception->getWrappedExceptions();
100+
} elseif ($exception instanceof HandlerFailedException && method_exists($exception, 'getNestedExceptions')) {
98101
$exception = $exception->getNestedExceptions();
99-
} elseif ($exception instanceof DelayedMessageHandlingException) {
102+
} elseif ($exception instanceof DelayedMessageHandlingException && method_exists($exception, 'getExceptions')) {
100103
$exception = $exception->getExceptions();
101104
}
102105

src/Tracing/HttpClient/AbstractTraceableHttpClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ private static function shouldAttachTracingHeaders(?ClientInterface $client, Uri
138138

139139
// Check if the request destination is allow listed in the trace_propagation_targets option.
140140
if (
141-
null !== $sdkOptions->getTracePropagationTargets() &&
141+
null !== $sdkOptions->getTracePropagationTargets()
142142
// Due to BC, we treat an empty array (the default) as all hosts are allow listed
143-
(
144-
[] === $sdkOptions->getTracePropagationTargets() ||
145-
\in_array($uri->getHost(), $sdkOptions->getTracePropagationTargets())
143+
&& (
144+
[] === $sdkOptions->getTracePropagationTargets()
145+
|| \in_array($uri->getHost(), $sdkOptions->getTracePropagationTargets())
146146
)
147147
) {
148148
return true;

tests/End2End/App/Messenger/FooMessageHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
namespace Sentry\SentryBundle\Tests\End2End\App\Messenger;
66

77
use Symfony\Component\Messenger\Exception\UnrecoverableExceptionInterface;
8-
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
98

10-
class FooMessageHandler implements MessageHandlerInterface
9+
class FooMessageHandler
1110
{
1211
public function __invoke(FooMessage $message): void
1312
{

tests/End2End/App/messenger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ services:
77

88
Sentry\SentryBundle\Tests\End2End\App\Messenger\FooMessageHandler:
99
class: \Sentry\SentryBundle\Tests\End2End\App\Messenger\FooMessageHandler
10+
tags:
11+
- { name: messenger.message_handler }
1012

1113
Sentry\SentryBundle\Tests\End2End\App\Controller\MessengerController:
1214
autowire: true

tests/End2End/End2EndTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ public function testNotice(): void
198198

199199
public function testCommand(): void
200200
{
201-
self::bootKernel();
202-
$application = new Application(self::$kernel);
201+
$application = new Application(self::bootKernel());
203202

204203
try {
205204
$application->doRun(new ArgvInput(['bin/console', 'main-command', '--option1', '--option2=foo', 'bar']), new NullOutput());

tests/EventListener/ErrorListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handleExceptionEventDataProvider(): \Generator
6666
new ExceptionEvent(
6767
$this->createMock(HttpKernelInterface::class),
6868
new Request(),
69-
HttpKernelInterface::MASTER_REQUEST,
69+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST,
7070
new \Exception()
7171
),
7272
];

tests/EventListener/LoginListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testHandleKernelRequestEvent(TokenInterface $token, ?UserDataBag
8888
$this->listener->handleKernelRequestEvent(new RequestEvent(
8989
$this->createMock(HttpKernelInterface::class),
9090
new Request(),
91-
HttpKernelInterface::MASTER_REQUEST
91+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
9292
));
9393

9494
$event = $scope->applyToEvent(Event::createEvent());
@@ -273,7 +273,7 @@ public function testHandleKernelRequestEventDoesNothingIfTokenIsNotSet(): void
273273
$this->listener->handleKernelRequestEvent(new RequestEvent(
274274
$this->createMock(HttpKernelInterface::class),
275275
new Request(),
276-
HttpKernelInterface::MASTER_REQUEST
276+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
277277
));
278278
}
279279

tests/EventListener/RequestListenerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
8282
new RequestEvent(
8383
$this->createMock(HttpKernelInterface::class),
8484
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
85-
HttpKernelInterface::MASTER_REQUEST
85+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
8686
),
8787
$this->getMockedClientWithOptions(new Options(['send_default_pii' => false])),
8888
new UserDataBag(),
@@ -93,7 +93,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
9393
new RequestEvent(
9494
$this->createMock(HttpKernelInterface::class),
9595
new Request(),
96-
HttpKernelInterface::MASTER_REQUEST
96+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
9797
),
9898
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
9999
new UserDataBag(),
@@ -104,7 +104,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
104104
new RequestEvent(
105105
$this->createMock(HttpKernelInterface::class),
106106
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
107-
HttpKernelInterface::MASTER_REQUEST
107+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
108108
),
109109
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
110110
new UserDataBag('foo_user'),
@@ -115,7 +115,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
115115
new RequestEvent(
116116
$this->createMock(HttpKernelInterface::class),
117117
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
118-
HttpKernelInterface::MASTER_REQUEST
118+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
119119
),
120120
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
121121
new UserDataBag('foo_user', null, '::1'),
@@ -168,7 +168,7 @@ static function () {
168168
static function () {
169169
},
170170
new Request(),
171-
HttpKernelInterface::MASTER_REQUEST
171+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
172172
),
173173
[],
174174
];
@@ -179,7 +179,7 @@ static function () {
179179
static function () {
180180
},
181181
new Request([], [], ['_route' => 'homepage']),
182-
HttpKernelInterface::MASTER_REQUEST
182+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
183183
),
184184
[
185185
'route' => 'homepage',

tests/EventListener/SubRequestListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testHandleKernelRequestEvent(RequestEvent $event): void
5353
public function handleKernelRequestEventDataProvider(): \Generator
5454
{
5555
yield [
56-
new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST),
56+
new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST),
5757
];
5858

5959
yield [
@@ -80,7 +80,7 @@ public function testHandleKernelFinishRequestEvent($event): void
8080
public function handleKernelFinishRequestEventDataProvider(): \Generator
8181
{
8282
yield [
83-
new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST),
83+
new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), \defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST),
8484
];
8585

8686
yield [

tests/EventListener/TracingRequestListenerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testHandleKernelRequestEvent(Options $options, Request $request,
7878
$this->listener->handleKernelRequestEvent(new RequestEvent(
7979
$this->createMock(HttpKernelInterface::class),
8080
$request,
81-
HttpKernelInterface::MASTER_REQUEST
81+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
8282
));
8383
}
8484

@@ -427,7 +427,7 @@ public function testHandleResponseRequestEvent(): void
427427
$this->listener->handleKernelResponseEvent(new ResponseEvent(
428428
$this->createMock(HttpKernelInterface::class),
429429
new Request(),
430-
HttpKernelInterface::MASTER_REQUEST,
430+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST,
431431
new Response()
432432
));
433433

@@ -444,7 +444,7 @@ public function testHandleResponseRequestEventDoesNothingIfNoTransactionIsSetOnH
444444
$this->listener->handleKernelResponseEvent(new ResponseEvent(
445445
$this->createMock(HttpKernelInterface::class),
446446
new Request(),
447-
HttpKernelInterface::MASTER_REQUEST,
447+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST,
448448
new Response()
449449
));
450450
}

tests/EventListener/TracingSubRequestListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testHandleKernelRequestEventDoesNothingIfRequestTypeIsMasterRequ
146146
$this->listener->handleKernelRequestEvent(new RequestEvent(
147147
$this->createMock(HttpKernelInterface::class),
148148
new Request(),
149-
HttpKernelInterface::MASTER_REQUEST
149+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
150150
));
151151
}
152152

@@ -191,7 +191,7 @@ public function testHandleKernelFinishRequestEventDoesNothingIfRequestTypeIsMast
191191
$this->listener->handleKernelFinishRequestEvent(new FinishRequestEvent(
192192
$this->createMock(HttpKernelInterface::class),
193193
new Request(),
194-
HttpKernelInterface::MASTER_REQUEST
194+
\defined(HttpKernelInterface::class . '::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST
195195
));
196196
}
197197

0 commit comments

Comments
 (0)