Skip to content

Commit 279811c

Browse files
Add support for symfony 6
1 parent b013a88 commit 279811c

File tree

4 files changed

+107
-70
lines changed

4 files changed

+107
-70
lines changed

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"php-http/discovery": "^1.11",
2525
"sentry/sdk": "^3.1",
2626
"symfony/cache-contracts": "^1.1||^2.4",
27-
"symfony/config": "^3.4.44||^4.4.20||^5.0.11",
28-
"symfony/console": "^3.4.44||^4.4.20||^5.0.11",
29-
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11",
30-
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11",
31-
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11",
27+
"symfony/config": "^3.4.44||^4.4.20||^5.0.11|^6.0",
28+
"symfony/console": "^3.4.44||^4.4.20||^5.0.11|^6.0",
29+
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11|^6.0",
30+
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11|^6.0",
31+
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11|^6.0",
3232
"symfony/polyfill-php80": "^1.22",
3333
"symfony/psr-http-message-bridge": "^1.2||^2.0",
34-
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11"
34+
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11|^6.0"
3535
},
3636
"require-dev": {
3737
"doctrine/dbal": "^2.13||^3.0",
@@ -45,15 +45,15 @@
4545
"phpstan/phpstan": "^0.12",
4646
"phpstan/phpstan-phpunit": "^0.12",
4747
"phpunit/phpunit": "^8.5||^9.0",
48-
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11",
49-
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11",
50-
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11",
51-
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11",
52-
"symfony/messenger": "^4.4.20||^5.0.11",
48+
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11|^6.0",
49+
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11|^6.0",
50+
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11|^6.0",
51+
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11|^6.0",
52+
"symfony/messenger": "^4.4.20||^5.0.11|^6.0",
5353
"symfony/monolog-bundle": "^3.4",
5454
"symfony/phpunit-bridge": "^5.2.6",
55-
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11",
56-
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11",
55+
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11|^6.0",
56+
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11|^6.0",
5757
"vimeo/psalm": "^4.3"
5858
},
5959
"suggest": {

src/EventListener/RequestListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
6767
$token = $this->tokenStorage->getToken();
6868
}
6969

70-
if (null !== $token && $token->isAuthenticated() && null !== $token->getUser()) {
70+
if (null !== $token
71+
&& (!method_exists($token, 'isAuthenticated') || $token->isAuthenticated())
72+
&& null !== $token->getUser()
73+
) {
7174
$userData->setUsername($this->getUsername($token->getUser()));
7275
}
7376

src/Tracing/Cache/TraceableCacheAdapterTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Sentry\Tracing\SpanContext;
1010
use Symfony\Component\Cache\Adapter\AdapterInterface;
1111
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
12+
use Symfony\Component\Cache\CacheItem;
1213
use Symfony\Component\Cache\PruneableInterface;
1314
use Symfony\Component\Cache\ResettableInterface;
1415
use Symfony\Contracts\Cache\CacheInterface;
@@ -35,7 +36,7 @@ trait TraceableCacheAdapterTrait
3536
/**
3637
* {@inheritdoc}
3738
*/
38-
public function getItem($key)
39+
public function getItem($key): CacheItem
3940
{
4041
return $this->traceFunction('cache.get_item', function () use ($key) {
4142
return $this->decoratedAdapter->getItem($key);
@@ -44,8 +45,10 @@ public function getItem($key)
4445

4546
/**
4647
* {@inheritdoc}
48+
*
49+
* @return CacheItem[]
4750
*/
48-
public function getItems(array $keys = [])
51+
public function getItems(array $keys = []): iterable
4952
{
5053
return $this->traceFunction('cache.get_items', function () use ($keys) {
5154
return $this->decoratedAdapter->getItems($keys);

tests/EventListener/RequestListenerTest.php

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public function __construct()
134134
{
135135
parent::__construct();
136136

137-
$this->setAuthenticated(false);
137+
if (method_exists($this, 'setAuthenticated')) {
138+
$this->setAuthenticated(false);
139+
}
138140
}
139141

140142
public function getCredentials()
@@ -157,7 +159,9 @@ public function __construct()
157159
{
158160
parent::__construct();
159161

160-
$this->setAuthenticated(true);
162+
if (method_exists($this, 'setAuthenticated')) {
163+
$this->setAuthenticated(true);
164+
}
161165
}
162166

163167
public function getCredentials()
@@ -180,7 +184,9 @@ public function __construct()
180184
{
181185
parent::__construct();
182186

183-
$this->setAuthenticated(true);
187+
if (method_exists($this, 'setAuthenticated')) {
188+
$this->setAuthenticated(true);
189+
}
184190
$this->setUser('foo_user');
185191
}
186192

@@ -204,7 +210,9 @@ public function __construct()
204210
{
205211
parent::__construct();
206212

207-
$this->setAuthenticated(true);
213+
if (method_exists($this, 'setAuthenticated')) {
214+
$this->setAuthenticated(true);
215+
}
208216
$this->setUser(new class() extends UserStub {
209217
public function getUserIdentifier(): string
210218
{
@@ -233,7 +241,10 @@ public function __construct()
233241
{
234242
parent::__construct();
235243

236-
$this->setAuthenticated(true);
244+
if (method_exists($this, 'setAuthenticated')) {
245+
$this->setAuthenticated(true);
246+
}
247+
237248
$this->setUser(new class() implements \Stringable {
238249
public function __toString(): string
239250
{
@@ -305,7 +316,9 @@ public function __construct()
305316
{
306317
parent::__construct();
307318

308-
$this->setAuthenticated(false);
319+
if (method_exists($this, 'setAuthenticated')) {
320+
$this->setAuthenticated(false);
321+
}
309322
}
310323

311324
public function getCredentials()
@@ -328,7 +341,9 @@ public function __construct()
328341
{
329342
parent::__construct();
330343

331-
$this->setAuthenticated(true);
344+
if (method_exists($this, 'setAuthenticated')) {
345+
$this->setAuthenticated(true);
346+
}
332347
}
333348

334349
public function getCredentials()
@@ -339,29 +354,32 @@ public function getCredentials()
339354
UserDataBag::createFromUserIpAddress('127.0.0.1'),
340355
];
341356

342-
yield 'token.authenticated = TRUE && token.user INSTANCEOF string' => [
343-
new RequestEvent(
344-
$this->createMock(HttpKernelInterface::class),
345-
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
346-
HttpKernelInterface::MASTER_REQUEST
347-
),
348-
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
349-
new class() extends AbstractToken {
350-
public function __construct()
351-
{
352-
parent::__construct();
357+
if (Kernel::VERSION_ID < 60000) {
358+
yield 'token.authenticated = TRUE && token.user INSTANCEOF string' => [
359+
new RequestEvent(
360+
$this->createMock(HttpKernelInterface::class),
361+
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
362+
HttpKernelInterface::MASTER_REQUEST
363+
),
364+
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
365+
new class() extends AbstractToken {
366+
public function __construct()
367+
{
368+
parent::__construct();
353369

354-
$this->setAuthenticated(true);
355-
$this->setUser('foo_user');
356-
}
370+
$this->setAuthenticated(true);
357371

358-
public function getCredentials()
359-
{
360-
return null;
361-
}
362-
},
363-
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
364-
];
372+
$this->setUser('foo_user');
373+
}
374+
375+
public function getCredentials()
376+
{
377+
return null;
378+
}
379+
},
380+
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
381+
];
382+
}
365383

366384
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS' => [
367385
new RequestEvent(
@@ -392,34 +410,39 @@ public function getUserIdentifier(): string
392410
];
393411
}
394412

395-
yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS' => [
396-
new RequestEvent(
397-
$this->createMock(HttpKernelInterface::class),
398-
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
399-
HttpKernelInterface::MASTER_REQUEST
400-
),
401-
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
402-
new class() extends AbstractToken {
403-
public function __construct()
404-
{
405-
parent::__construct();
413+
if (Kernel::VERSION_ID < 60000) {
414+
yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS' => [
415+
new RequestEvent(
416+
$this->createMock(HttpKernelInterface::class),
417+
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
418+
HttpKernelInterface::MASTER_REQUEST
419+
),
420+
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
421+
new class() extends AbstractToken {
422+
public function __construct()
423+
{
424+
parent::__construct();
406425

407-
$this->setAuthenticated(true);
408-
$this->setUser(new class() implements \Stringable {
409-
public function __toString(): string
410-
{
411-
return 'foo_user';
426+
if (method_exists($this, 'setAuthenticated')) {
427+
$this->setAuthenticated(true);
412428
}
413-
});
414-
}
415429

416-
public function getCredentials()
417-
{
418-
return null;
419-
}
420-
},
421-
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
422-
];
430+
$this->setUser(new class() implements \Stringable {
431+
public function __toString(): string
432+
{
433+
return 'foo_user';
434+
}
435+
});
436+
}
437+
438+
public function getCredentials()
439+
{
440+
return null;
441+
}
442+
},
443+
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
444+
];
445+
}
423446

424447
yield 'request.clientIp IS NULL' => [
425448
new RequestEvent(
@@ -564,7 +587,10 @@ public function __construct(UserInterface $user)
564587
{
565588
parent::__construct();
566589

567-
$this->setAuthenticated(true);
590+
if (method_exists($this, 'setAuthenticated')) {
591+
$this->setAuthenticated(true);
592+
}
593+
568594
$this->setUser($user);
569595
}
570596

@@ -581,6 +607,11 @@ public function getUsername(): string
581607
return 'foo_user';
582608
}
583609

610+
public function getUserIdentifier(): string
611+
{
612+
return 'foo_user';
613+
}
614+
584615
public function getRoles(): array
585616
{
586617
return [];

0 commit comments

Comments
 (0)