@@ -254,7 +254,7 @@ public function testIfTokenIsDeauthenticated()
254254 {
255255 $ tokenStorage = new TokenStorage ();
256256 $ refreshedUser = new User ('foobar ' , 'baz ' );
257- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )]);
257+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )]);
258258
259259 $ this ->assertNull ($ tokenStorage ->getToken ());
260260 }
@@ -276,7 +276,7 @@ public function testRememberMeGetsCanceledIfTokenIsDeauthenticated()
276276 $ rememberMeServices = $ this ->createMock (RememberMeServicesInterface::class);
277277 $ rememberMeServices ->expects ($ this ->once ())->method ('loginFail ' );
278278
279- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], null , $ rememberMeServices );
279+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], null , $ rememberMeServices );
280280
281281 $ this ->assertNull ($ tokenStorage ->getToken ());
282282 }
@@ -285,7 +285,7 @@ public function testTryAllUserProvidersUntilASupportingUserProviderIsFound()
285285 {
286286 $ tokenStorage = new TokenStorage ();
287287 $ refreshedUser = new User ('foobar ' , 'baz ' );
288- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
288+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
289289
290290 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
291291 }
@@ -294,30 +294,30 @@ public function testNextSupportingUserProviderIsTriedIfPreviousSupportingUserPro
294294 {
295295 $ tokenStorage = new TokenStorage ();
296296 $ refreshedUser = new User ('foobar ' , 'baz ' );
297- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new SupportingUserProvider ( ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
297+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider ( true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], $ refreshedUser );
298298
299299 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
300300 }
301301
302302 public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProviders ()
303303 {
304304 $ tokenStorage = new TokenStorage ();
305- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ()]);
305+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ()]);
306306
307307 $ this ->assertNull ($ tokenStorage ->getToken ());
308308 }
309309
310310 public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered ()
311311 {
312312 $ this ->expectException ('RuntimeException ' );
313- $ this ->handleEventWithPreviousSession (new TokenStorage (), [new NotSupportingUserProvider (), new NotSupportingUserProvider ()]);
313+ $ this ->handleEventWithPreviousSession (new TokenStorage (), [new NotSupportingUserProvider (false ), new NotSupportingUserProvider (true )]);
314314 }
315315
316316 public function testAcceptsProvidersAsTraversable ()
317317 {
318318 $ tokenStorage = new TokenStorage ();
319319 $ refreshedUser = new User ('foobar ' , 'baz ' );
320- $ this ->handleEventWithPreviousSession ($ tokenStorage , new \ArrayObject ([new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )]), $ refreshedUser );
320+ $ this ->handleEventWithPreviousSession ($ tokenStorage , new \ArrayObject ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )]), $ refreshedUser );
321321
322322 $ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
323323 }
@@ -343,7 +343,7 @@ public function testDeauthenticatedEvent()
343343 $ this ->assertNotEquals ($ event ->getRefreshedToken ()->getUser (), $ user );
344344 });
345345
346- $ listener = new ContextListener ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ($ refreshedUser )], 'context_key ' , null , $ eventDispatcher );
346+ $ listener = new ContextListener ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ($ refreshedUser )], 'context_key ' , null , $ eventDispatcher );
347347 $ listener (new RequestEvent ($ this ->getMockBuilder (HttpKernelInterface::class)->getMock (), $ request , HttpKernelInterface::MASTER_REQUEST ));
348348
349349 $ this ->assertNull ($ tokenStorage ->getToken ());
@@ -398,14 +398,26 @@ private function handleEventWithPreviousSession(TokenStorageInterface $tokenStor
398398
399399class NotSupportingUserProvider implements UserProviderInterface
400400{
401+ /** @var bool */
402+ private $ throwsUnsupportedException ;
403+
404+ public function __construct ($ throwsUnsupportedException )
405+ {
406+ $ this ->throwsUnsupportedException = $ throwsUnsupportedException ;
407+ }
408+
401409 public function loadUserByUsername ($ username )
402410 {
403411 throw new UsernameNotFoundException ();
404412 }
405413
406414 public function refreshUser (UserInterface $ user )
407415 {
408- throw new UnsupportedUserException ();
416+ if ($ this ->throwsUnsupportedException ) {
417+ throw new UnsupportedUserException ();
418+ }
419+
420+ return $ user ;
409421 }
410422
411423 public function supportsClass ($ class )
0 commit comments