|
10 | 10 | use PHPUnit\Framework\TestCase; |
11 | 11 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
12 | 12 | use Symfony\Component\Security\Core\Authentication\Token\NullToken; |
| 13 | +use Symfony\Component\Security\Core\Authentication\Token\OfflineTokenInterface; |
13 | 14 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
14 | 15 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
15 | 16 | use Symfony\Component\Security\Core\User\InMemoryUser; |
@@ -113,7 +114,7 @@ public function testATokenIsCreatedAndAddedToStorageWhenAGuestUserWithoutASessio |
113 | 114 | public function testAnAuthenticatedUserFromASharedSessionIsAuthenticated(): void |
114 | 115 | { |
115 | 116 | $token = new UsernamePasswordToken( |
116 | | - new InMemoryUser('user', 'password'), |
| 117 | + new InMemoryUser('user', 'password', ['ROLE_USER']), |
117 | 118 | 'main', |
118 | 119 | ['ROLE_USER'], |
119 | 120 | ); |
@@ -152,6 +153,13 @@ public function testAnAuthenticatedUserFromASharedSessionIsAuthenticated(): void |
152 | 153 | ->method('addToken') |
153 | 154 | ->with($storageIdentifier, self::isInstanceOf(TokenInterface::class)); |
154 | 155 |
|
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); |
156 | 164 | } |
157 | 165 | } |
0 commit comments