@@ -253,7 +253,7 @@ public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
253253 public function testIfTokenIsDeauthenticated ()
254254 {
255255 $ refreshedUser = new User ('foobar ' , 'baz ' );
256- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )]);
256+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )]);
257257
258258 $ this ->assertNull ($ tokenStorage ->getToken ());
259259 }
@@ -275,44 +275,44 @@ public function testRememberMeGetsCanceledIfTokenIsDeauthenticated()
275275 $ rememberMeServices = $ this ->createMock (RememberMeServicesInterface::class);
276276 $ rememberMeServices ->expects ($ this ->once ())->method ('loginFail ' );
277277
278- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], null , $ rememberMeServices );
278+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], null , $ rememberMeServices );
279279
280280 $ this ->assertNull ($ tokenStorage ->getToken ());
281281 }
282282
283283 public function testTryAllUserProvidersUntilASupportingUserProviderIsFound ()
284284 {
285285 $ refreshedUser = new User ('foobar ' , 'baz ' );
286- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
286+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
287287
288288 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
289289 }
290290
291291 public function testNextSupportingUserProviderIsTriedIfPreviousSupportingUserProviderDidNotLoadTheUser ()
292292 {
293293 $ refreshedUser = new User ('foobar ' , 'baz ' );
294- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new SupportingUserProvider ( ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
294+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider ( true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
295295
296296 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
297297 }
298298
299299 public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProviders ()
300300 {
301- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new SupportingUserProvider ()]);
301+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ()]);
302302
303303 $ this ->assertNull ($ tokenStorage ->getToken ());
304304 }
305305
306306 public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered ()
307307 {
308308 $ this ->expectException ('RuntimeException ' );
309- $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new NotSupportingUserProvider ()]);
309+ $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (false ), new NotSupportingUserProvider (true )]);
310310 }
311311
312312 public function testAcceptsProvidersAsTraversable ()
313313 {
314314 $ refreshedUser = new User ('foobar ' , 'baz ' );
315- $ tokenStorage = $ this ->handleEventWithPreviousSession (new \ArrayObject ([new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )]), $ refreshedUser );
315+ $ tokenStorage = $ this ->handleEventWithPreviousSession (new \ArrayObject ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )]), $ refreshedUser );
316316
317317 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
318318 }
@@ -338,7 +338,7 @@ public function testDeauthenticatedEvent()
338338 $ this ->assertNotEquals ($ event ->getRefreshedToken ()->getUser (), $ user );
339339 });
340340
341- $ listener = new ContextListener ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], 'context_key ' , null , $ eventDispatcher );
341+ $ listener = new ContextListener ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], 'context_key ' , null , $ eventDispatcher );
342342 $ listener (new RequestEvent ($ this ->getMockBuilder (HttpKernelInterface::class)->getMock (), $ request , HttpKernelInterface::MASTER_REQUEST ));
343343
344344 $ this ->assertNull ($ tokenStorage ->getToken ());
@@ -422,14 +422,26 @@ private function handleEventWithPreviousSession($userProviders, UserInterface $u
422422
423423class NotSupportingUserProvider implements UserProviderInterface
424424{
425+ /** @var bool */
426+ private $ throwsUnsupportedException ;
427+
428+ public function __construct ($ throwsUnsupportedException )
429+ {
430+ $ this ->throwsUnsupportedException = $ throwsUnsupportedException ;
431+ }
432+
425433 public function loadUserByUsername ($ username ): UserInterface
426434 {
427435 throw new UsernameNotFoundException ();
428436 }
429437
430438 public function refreshUser (UserInterface $ user ): UserInterface
431439 {
432- throw new UnsupportedUserException ();
440+ if ($ this ->throwsUnsupportedException ) {
441+ throw new UnsupportedUserException ();
442+ }
443+
444+ return $ user ;
433445 }
434446
435447 public function supportsClass ($ class ): bool
0 commit comments