Skip to content

Commit 725ed62

Browse files
committed
Fixed compatibility with Symfony 6.4+
1 parent 1b0ae01 commit 725ed62

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/Controller/LoginControllerTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2727
use Symfony\Component\Security\Core\Security as DeprecatedSecurity;
2828
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
29+
use Symfony\Component\Security\Http\SecurityRequestAttributes;
2930
use Twig\Environment;
3031

3132
final class LoginControllerTest extends TestCase
@@ -211,6 +212,12 @@ private function createController(): LoginController
211212

212213
private function getSecurityErrorKey(): string
213214
{
215+
// Symfony 6.4+ compatibility
216+
if (class_exists(SecurityRequestAttributes::class)) {
217+
return SecurityRequestAttributes::AUTHENTICATION_ERROR;
218+
}
219+
220+
// Symfony 5.4 & <6.4 compatibility
214221
return class_exists(Security::class) ? Security::AUTHENTICATION_ERROR : DeprecatedSecurity::AUTHENTICATION_ERROR;
215222
}
216223
}

tests/Functional/Controller/LoginControllerTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\HttpClient\MockHttpClient;
2121
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2222
use Symfony\Component\Security\Core\Security as DeprecatedSecurity;
23+
use Symfony\Component\Security\Http\SecurityRequestAttributes;
2324
use Symfony\Contracts\HttpClient\HttpClientInterface;
2425

2526
final class LoginControllerTest extends WebTestCase
@@ -84,6 +85,12 @@ public function testLoginPageWithError(): void
8485

8586
private function getSecurityErrorKey(): string
8687
{
88+
// Symfony 6.4+ compatibility
89+
if (class_exists(SecurityRequestAttributes::class)) {
90+
return SecurityRequestAttributes::AUTHENTICATION_ERROR;
91+
}
92+
93+
// Symfony 5.4 & <6.4 compatibility
8794
return class_exists(Security::class) ? Security::AUTHENTICATION_ERROR : DeprecatedSecurity::AUTHENTICATION_ERROR;
8895
}
8996
}

0 commit comments

Comments
 (0)