Skip to content

Commit

Permalink
fix(tests): deprecate warning in Symfony 5.4 for setAuthenticated (#847)
Browse files Browse the repository at this point in the history
Co-authored-by: Michi Hoffmann <[email protected]>
Co-authored-by: Alex Bouma <[email protected]>
  • Loading branch information
3 people committed Jun 4, 2024
1 parent 7a05d39 commit 0c11485
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 75 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ parameters:
count: 2
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, Closure\\(array\\)\\: mixed given\\.$#"
count: 1
path: src/ErrorTypesParser.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -300,11 +295,6 @@ parameters:
count: 1
path: tests/EventListener/LoginListenerTest.php

-
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\\.$#"
count: 1
path: tests/EventListener/LoginListenerTest.php

-
message: "#^Parameter \\#2 \\$firewallName of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\SwitchUserToken constructor expects string, null given\\.$#"
count: 1
Expand All @@ -320,11 +310,6 @@ parameters:
count: 1
path: tests/EventListener/LoginListenerTest.php

-
message: "#^Parameter \\#5 \\$originatedFromUri of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\SwitchUserToken constructor expects string\\|null, Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub given\\.$#"
count: 1
path: tests/EventListener/LoginListenerTest.php

-
message: "#^Access to undefined constant Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface\\:\\:MASTER_REQUEST\\.$#"
count: 6
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
reportUnmatchedIgnoredErrors: true
level: 9
paths:
- src
Expand Down
12 changes: 3 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/aliases.php</file>
</exclude>
</coverage>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<file>src/aliases.php</file>
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
Expand Down
16 changes: 15 additions & 1 deletion src/ErrorTypesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ private static function convertErrorConstants(string $value): string
{
$output = preg_replace_callback('/(E_[A-Z_]+)/', static function (array $matches) {
if (\defined($matches[1])) {
return \constant($matches[1]);
$constant = \constant($matches[1]);

if (\is_string($constant)) {
return $constant;
} elseif (\is_int($constant)) {
return (string) $constant;
} elseif (\is_array($constant)) {
return implode(' | ', array_map(static function ($value) {
return \is_string($value) ? $value : (string) $value;
}, $constant));
} elseif (\is_object($constant)) {
return \get_class($constant);
} else { // Non-scalar values
return '';
}
}

return $matches[0];
Expand Down
7 changes: 7 additions & 0 deletions tests/End2End/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load(__DIR__ . '/deprecations_for_5.yml');
}

if (self::VERSION_ID >= 50400 && self::VERSION_ID <= 60000) {
// Check if class for Messenger is present (component symfony/messenger is not mandatory)
if (interface_exists(MessageBusInterface::class)) {
$loader->load(__DIR__ . '/deprecations_for_54.yml');
}
}

if (self::VERSION_ID >= 60000) {
$loader->load(__DIR__ . '/deprecations_for_6.yml');
}
Expand Down
3 changes: 3 additions & 0 deletions tests/End2End/App/deprecations_for_54.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
messenger:
reset_on_message: true
3 changes: 3 additions & 0 deletions tests/ErrorTypesParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ public function parseThrowsExceptionIfArgumentContainsInvalidCharactersDataProvi
yield ['('];
yield [')'];
yield ['()'];
// Non scalar values (probably misstypes, but still valid PHP code)
yield ['[8, 8192]'];
yield [\stdClass::class];
}
}
Loading

0 comments on commit 0c11485

Please sign in to comment.