Skip to content

Commit 0de9450

Browse files
committed
Various improvements to the tests
1 parent c8510ee commit 0de9450

File tree

5 files changed

+121
-222
lines changed

5 files changed

+121
-222
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ parameters:
2020
count: 1
2121
path: src/EventListener/ErrorListener.php
2222

23+
-
24+
message: "#^Method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\TokenInterface\\:\\:isAuthenticated\\(\\) invoked with 1 parameter, 0 required\\.$#"
25+
count: 1
26+
path: src/EventListener/RequestListener.php
27+
2328
-
2429
message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
2530
count: 1
@@ -107,7 +112,7 @@ parameters:
107112

108113
-
109114
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
110-
count: 8
115+
count: 9
111116
path: tests/EventListener/RequestListenerTest.php
112117

113118
-

psalm-baseline.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="4.11.1@e33492398bd4e5e2ab60e331d445979bd83feecd">
2+
<files psalm-version="4.12.0@e42bc4a23f67acba28a23bb09c348e2ff38a1d87">
33
<file src="src/DependencyInjection/SentryExtension.php">
44
<UndefinedClass occurrences="1">
55
<code>FatalErrorException</code>
@@ -13,6 +13,24 @@
1313
<code>public function __construct(HubInterface $hub, bool $captureErrors = true)</code>
1414
</MethodSignatureMismatch>
1515
</file>
16+
<file src="src/EventListener/ErrorListener.php">
17+
<RedundantCondition occurrences="1">
18+
<code>$event instanceof ExceptionEvent</code>
19+
</RedundantCondition>
20+
<UndefinedMethod occurrences="1">
21+
<code>getException</code>
22+
</UndefinedMethod>
23+
</file>
24+
<file src="src/EventListener/RequestListener.php">
25+
<TooManyArguments occurrences="1">
26+
<code>isAuthenticated</code>
27+
</TooManyArguments>
28+
</file>
29+
<file src="src/Tracing/Cache/TraceableCacheAdapterTrait.php">
30+
<ImplementedReturnTypeMismatch occurrences="1">
31+
<code>iterable</code>
32+
</ImplementedReturnTypeMismatch>
33+
</file>
1634
<file src="src/Tracing/Doctrine/DBAL/TracingDriverForV2.php">
1735
<UndefinedClass occurrences="1">
1836
<code>ExceptionConverterDriver</code>

src/EventListener/ErrorListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct(HubInterface $hub)
3434
*/
3535
public function handleExceptionEvent(ErrorListenerExceptionEvent $event): void
3636
{
37-
/** @psalm-suppress RedundantCondition */
3837
if ($event instanceof ExceptionEvent) {
3938
$this->hub->captureException($event->getThrowable());
4039
} else {

src/EventListener/RequestListener.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sentry\State\Scope;
99
use Sentry\UserDataBag;
1010
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1112
use Symfony\Component\Security\Core\User\UserInterface;
1213

1314
/**
@@ -67,10 +68,7 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
6768
$token = $this->tokenStorage->getToken();
6869
}
6970

70-
if (null !== $token
71-
&& (!method_exists($token, 'isAuthenticated') || $token->isAuthenticated(false))
72-
&& null !== $token->getUser()
73-
) {
71+
if ($this->isTokenAuthenticated($token)) {
7472
$userData->setUsername($this->getUsername($token->getUser()));
7573
}
7674

@@ -127,4 +125,17 @@ private function getUsername($user): ?string
127125

128126
return null;
129127
}
128+
129+
private function isTokenAuthenticated(?TokenInterface $token): bool
130+
{
131+
if (null === $token) {
132+
return false;
133+
}
134+
135+
if (method_exists($token, 'isAuthenticated') && !$token->isAuthenticated(false)) {
136+
return false;
137+
}
138+
139+
return null !== $token->getUser();
140+
}
130141
}

0 commit comments

Comments
 (0)