@@ -254,7 +254,7 @@ public function testIfTokenIsDeauthenticated()
254
254
{
255
255
$ tokenStorage = new TokenStorage ();
256
256
$ 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 )]);
258
258
259
259
$ this ->assertNull ($ tokenStorage ->getToken ());
260
260
}
@@ -276,7 +276,7 @@ public function testRememberMeGetsCanceledIfTokenIsDeauthenticated()
276
276
$ rememberMeServices = $ this ->createMock (RememberMeServicesInterface::class);
277
277
$ rememberMeServices ->expects ($ this ->once ())->method ('loginFail ' );
278
278
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 );
280
280
281
281
$ this ->assertNull ($ tokenStorage ->getToken ());
282
282
}
@@ -285,7 +285,7 @@ public function testTryAllUserProvidersUntilASupportingUserProviderIsFound()
285
285
{
286
286
$ tokenStorage = new TokenStorage ();
287
287
$ 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 );
289
289
290
290
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
291
291
}
@@ -294,30 +294,30 @@ public function testNextSupportingUserProviderIsTriedIfPreviousSupportingUserPro
294
294
{
295
295
$ tokenStorage = new TokenStorage ();
296
296
$ 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 );
298
298
299
299
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
300
300
}
301
301
302
302
public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProviders ()
303
303
{
304
304
$ tokenStorage = new TokenStorage ();
305
- $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (), new SupportingUserProvider ()]);
305
+ $ this ->handleEventWithPreviousSession ($ tokenStorage , [new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ()]);
306
306
307
307
$ this ->assertNull ($ tokenStorage ->getToken ());
308
308
}
309
309
310
310
public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered ()
311
311
{
312
312
$ this ->expectException ('RuntimeException ' );
313
- $ this ->handleEventWithPreviousSession (new TokenStorage (), [new NotSupportingUserProvider (), new NotSupportingUserProvider ()]);
313
+ $ this ->handleEventWithPreviousSession (new TokenStorage (), [new NotSupportingUserProvider (false ), new NotSupportingUserProvider (true )]);
314
314
}
315
315
316
316
public function testAcceptsProvidersAsTraversable ()
317
317
{
318
318
$ tokenStorage = new TokenStorage ();
319
319
$ 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 );
321
321
322
322
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
323
323
}
@@ -343,7 +343,7 @@ public function testDeauthenticatedEvent()
343
343
$ this ->assertNotEquals ($ event ->getRefreshedToken ()->getUser (), $ user );
344
344
});
345
345
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 );
347
347
$ listener (new RequestEvent ($ this ->getMockBuilder (HttpKernelInterface::class)->getMock (), $ request , HttpKernelInterface::MASTER_REQUEST ));
348
348
349
349
$ this ->assertNull ($ tokenStorage ->getToken ());
@@ -398,14 +398,26 @@ private function handleEventWithPreviousSession(TokenStorageInterface $tokenStor
398
398
399
399
class NotSupportingUserProvider implements UserProviderInterface
400
400
{
401
+ /** @var bool */
402
+ private $ throwsUnsupportedException ;
403
+
404
+ public function __construct ($ throwsUnsupportedException )
405
+ {
406
+ $ this ->throwsUnsupportedException = $ throwsUnsupportedException ;
407
+ }
408
+
401
409
public function loadUserByUsername ($ username )
402
410
{
403
411
throw new UsernameNotFoundException ();
404
412
}
405
413
406
414
public function refreshUser (UserInterface $ user )
407
415
{
408
- throw new UnsupportedUserException ();
416
+ if ($ this ->throwsUnsupportedException ) {
417
+ throw new UnsupportedUserException ();
418
+ }
419
+
420
+ return $ user ;
409
421
}
410
422
411
423
public function supportsClass ($ class )
0 commit comments