Skip to content

Commit 0c11485

Browse files
shakarancleptricstayallive
authored
fix(tests): deprecate warning in Symfony 5.4 for setAuthenticated (#847)
Co-authored-by: Michi Hoffmann <[email protected]> Co-authored-by: Alex Bouma <[email protected]>
1 parent 7a05d39 commit 0c11485

8 files changed

+205
-75
lines changed

phpstan-baseline.neon

-15
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ parameters:
155155
count: 2
156156
path: src/DependencyInjection/SentryExtension.php
157157

158-
-
159-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, Closure\\(array\\)\\: mixed given\\.$#"
160-
count: 1
161-
path: src/ErrorTypesParser.php
162-
163158
-
164159
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
165160
count: 1
@@ -300,11 +295,6 @@ parameters:
300295
count: 1
301296
path: tests/EventListener/LoginListenerTest.php
302297

303-
-
304-
message: "#^Parameter \\#1 \\$user of method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\AbstractToken\\:\\:setUser\\(\\) expects Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface, string\\|Stringable\\|Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface given\\.$#"
305-
count: 1
306-
path: tests/EventListener/LoginListenerTest.php
307-
308298
-
309299
message: "#^Parameter \\#2 \\$firewallName of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\SwitchUserToken constructor expects string, null given\\.$#"
310300
count: 1
@@ -320,11 +310,6 @@ parameters:
320310
count: 1
321311
path: tests/EventListener/LoginListenerTest.php
322312

323-
-
324-
message: "#^Parameter \\#5 \\$originatedFromUri of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\SwitchUserToken constructor expects string\\|null, Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub given\\.$#"
325-
count: 1
326-
path: tests/EventListener/LoginListenerTest.php
327-
328313
-
329314
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
330315
count: 6

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5+
reportUnmatchedIgnoredErrors: true
56
level: 9
67
paths:
78
- src

phpunit.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020
<include>
2121
<directory suffix=".php">src</directory>
2222
</include>
23+
<exclude>
24+
<file>src/aliases.php</file>
25+
</exclude>
2326
</coverage>
2427

25-
<filter>
26-
<whitelist>
27-
<directory suffix=".php">src</directory>
28-
<exclude>
29-
<file>src/aliases.php</file>
30-
</exclude>
31-
</whitelist>
32-
</filter>
33-
3428
<listeners>
3529
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
3630
</listeners>

src/ErrorTypesParser.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ private static function convertErrorConstants(string $value): string
5454
{
5555
$output = preg_replace_callback('/(E_[A-Z_]+)/', static function (array $matches) {
5656
if (\defined($matches[1])) {
57-
return \constant($matches[1]);
57+
$constant = \constant($matches[1]);
58+
59+
if (\is_string($constant)) {
60+
return $constant;
61+
} elseif (\is_int($constant)) {
62+
return (string) $constant;
63+
} elseif (\is_array($constant)) {
64+
return implode(' | ', array_map(static function ($value) {
65+
return \is_string($value) ? $value : (string) $value;
66+
}, $constant));
67+
} elseif (\is_object($constant)) {
68+
return \get_class($constant);
69+
} else { // Non-scalar values
70+
return '';
71+
}
5872
}
5973

6074
return $matches[0];

tests/End2End/App/Kernel.php

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
4444
$loader->load(__DIR__ . '/deprecations_for_5.yml');
4545
}
4646

47+
if (self::VERSION_ID >= 50400 && self::VERSION_ID <= 60000) {
48+
// Check if class for Messenger is present (component symfony/messenger is not mandatory)
49+
if (interface_exists(MessageBusInterface::class)) {
50+
$loader->load(__DIR__ . '/deprecations_for_54.yml');
51+
}
52+
}
53+
4754
if (self::VERSION_ID >= 60000) {
4855
$loader->load(__DIR__ . '/deprecations_for_6.yml');
4956
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
messenger:
3+
reset_on_message: true

tests/ErrorTypesParserTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ public function parseThrowsExceptionIfArgumentContainsInvalidCharactersDataProvi
7171
yield ['('];
7272
yield [')'];
7373
yield ['()'];
74+
// Non scalar values (probably misstypes, but still valid PHP code)
75+
yield ['[8, 8192]'];
76+
yield [\stdClass::class];
7477
}
7578
}

0 commit comments

Comments
 (0)