@@ -253,7 +253,7 @@ public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
253
253
public function testIfTokenIsDeauthenticated ()
254
254
{
255
255
$ 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 )]);
257
257
258
258
$ this ->assertNull ($ tokenStorage ->getToken ());
259
259
}
@@ -275,44 +275,44 @@ public function testRememberMeGetsCanceledIfTokenIsDeauthenticated()
275
275
$ rememberMeServices = $ this ->createMock (RememberMeServicesInterface::class);
276
276
$ rememberMeServices ->expects ($ this ->once ())->method ('loginFail ' );
277
277
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 );
279
279
280
280
$ this ->assertNull ($ tokenStorage ->getToken ());
281
281
}
282
282
283
283
public function testTryAllUserProvidersUntilASupportingUserProviderIsFound ()
284
284
{
285
285
$ 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 );
287
287
288
288
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
289
289
}
290
290
291
291
public function testNextSupportingUserProviderIsTriedIfPreviousSupportingUserProviderDidNotLoadTheUser ()
292
292
{
293
293
$ 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 );
295
295
296
296
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
297
297
}
298
298
299
299
public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProviders ()
300
300
{
301
- $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new SupportingUserProvider ()]);
301
+ $ tokenStorage = $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (true ), new NotSupportingUserProvider ( false ), new SupportingUserProvider ()]);
302
302
303
303
$ this ->assertNull ($ tokenStorage ->getToken ());
304
304
}
305
305
306
306
public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered ()
307
307
{
308
308
$ this ->expectException ('RuntimeException ' );
309
- $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (), new NotSupportingUserProvider ()]);
309
+ $ this ->handleEventWithPreviousSession ([new NotSupportingUserProvider (false ), new NotSupportingUserProvider (true )]);
310
310
}
311
311
312
312
public function testAcceptsProvidersAsTraversable ()
313
313
{
314
314
$ 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 );
316
316
317
317
$ this ->assertSame ($ refreshedUser , $ tokenStorage ->getToken ()->getUser ());
318
318
}
@@ -338,7 +338,7 @@ public function testDeauthenticatedEvent()
338
338
$ this ->assertNotEquals ($ event ->getRefreshedToken ()->getUser (), $ user );
339
339
});
340
340
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 );
342
342
$ listener (new RequestEvent ($ this ->getMockBuilder (HttpKernelInterface::class)->getMock (), $ request , HttpKernelInterface::MASTER_REQUEST ));
343
343
344
344
$ this ->assertNull ($ tokenStorage ->getToken ());
@@ -422,14 +422,26 @@ private function handleEventWithPreviousSession($userProviders, UserInterface $u
422
422
423
423
class NotSupportingUserProvider implements UserProviderInterface
424
424
{
425
+ /** @var bool */
426
+ private $ throwsUnsupportedException ;
427
+
428
+ public function __construct ($ throwsUnsupportedException )
429
+ {
430
+ $ this ->throwsUnsupportedException = $ throwsUnsupportedException ;
431
+ }
432
+
425
433
public function loadUserByUsername ($ username ): UserInterface
426
434
{
427
435
throw new UsernameNotFoundException ();
428
436
}
429
437
430
438
public function refreshUser (UserInterface $ user ): UserInterface
431
439
{
432
- throw new UnsupportedUserException ();
440
+ if ($ this ->throwsUnsupportedException ) {
441
+ throw new UnsupportedUserException ();
442
+ }
443
+
444
+ return $ user ;
433
445
}
434
446
435
447
public function supportsClass ($ class ): bool
0 commit comments