Skip to content

Commit 17ead70

Browse files
committed
Adjust auth provider test for change in Symfony 7.3
1 parent b837940 commit 17ead70

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/Authentication/Provider/SessionAuthenticationProviderTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1212
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
13+
use Symfony\Component\Security\Core\Authentication\Token\OfflineTokenInterface;
1314
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1415
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1516
use Symfony\Component\Security\Core\User\InMemoryUser;
@@ -113,7 +114,7 @@ public function testATokenIsCreatedAndAddedToStorageWhenAGuestUserWithoutASessio
113114
public function testAnAuthenticatedUserFromASharedSessionIsAuthenticated(): void
114115
{
115116
$token = new UsernamePasswordToken(
116-
new InMemoryUser('user', 'password'),
117+
new InMemoryUser('user', 'password', ['ROLE_USER']),
117118
'main',
118119
['ROLE_USER'],
119120
);
@@ -152,6 +153,13 @@ public function testAnAuthenticatedUserFromASharedSessionIsAuthenticated(): void
152153
->method('addToken')
153154
->with($storageIdentifier, self::isInstanceOf(TokenInterface::class));
154155

155-
self::assertEquals($token, $this->provider->authenticate($connection));
156+
$authenticatedToken = $this->provider->authenticate($connection);
157+
158+
// After https://github.com/symfony/symfony/pull/59558 (introduced in Symfony 7.3), the roleNames property is lazily initialized so we need to trigger that
159+
if (interface_exists(OfflineTokenInterface::class)) {
160+
$authenticatedToken->getRoleNames();
161+
}
162+
163+
self::assertEquals($token, $authenticatedToken);
156164
}
157165
}

0 commit comments

Comments
 (0)