@@ -155,7 +155,10 @@ public function testLogin()
155
155
$ firewallAuthenticatorLocator
156
156
->expects ($ this ->once ())
157
157
->method ('getProvidedServices ' )
158
- ->willReturn (['security.authenticator.custom.dev ' => $ authenticator ])
158
+ ->willReturn ([
159
+ 'security.authenticator.custom.dev ' => $ authenticator ,
160
+ 'security.authenticator.remember_me.main ' => $ authenticator
161
+ ])
159
162
;
160
163
$ firewallAuthenticatorLocator
161
164
->expects ($ this ->once ())
@@ -274,6 +277,49 @@ public function testLoginWithoutRequestContext()
274
277
$ security ->login ($ user );
275
278
}
276
279
280
+ public function testLoginFailsWhenTooManyAuthenticatorsFound ()
281
+ {
282
+ $ request = new Request ();
283
+ $ authenticator = $ this ->createMock (AuthenticatorInterface::class);
284
+ $ requestStack = $ this ->createMock (RequestStack::class);
285
+ $ firewallMap = $ this ->createMock (FirewallMap::class);
286
+ $ firewall = new FirewallConfig ('main ' , 'main ' );
287
+ $ userAuthenticator = $ this ->createMock (UserAuthenticatorInterface::class);
288
+ $ user = $ this ->createMock (UserInterface::class);
289
+ $ userChecker = $ this ->createMock (UserCheckerInterface::class);
290
+
291
+ $ container = $ this ->createMock (ContainerInterface::class);
292
+ $ container
293
+ ->expects ($ this ->atLeastOnce ())
294
+ ->method ('get ' )
295
+ ->willReturnMap ([
296
+ ['request_stack ' , $ requestStack ],
297
+ ['security.firewall.map ' , $ firewallMap ],
298
+ ['security.authenticator.managers_locator ' , $ this ->createContainer ('main ' , $ userAuthenticator )],
299
+ ['security.user_checker_locator ' , $ this ->createContainer ('main ' , $ userChecker )],
300
+ ])
301
+ ;
302
+
303
+ $ requestStack ->expects ($ this ->once ())->method ('getCurrentRequest ' )->willReturn ($ request );
304
+ $ firewallMap ->expects ($ this ->once ())->method ('getFirewallConfig ' )->willReturn ($ firewall );
305
+
306
+ $ firewallAuthenticatorLocator = $ this ->createMock (ServiceProviderInterface::class);
307
+ $ firewallAuthenticatorLocator
308
+ ->expects ($ this ->once ())
309
+ ->method ('getProvidedServices ' )
310
+ ->willReturn ([
311
+ 'security.authenticator.custom.main ' => $ authenticator ,
312
+ 'security.authenticator.other.main ' => $ authenticator
313
+ ])
314
+ ;
315
+
316
+ $ security = new Security ($ container , ['main ' => $ firewallAuthenticatorLocator ]);
317
+
318
+ $ this ->expectException (\LogicException::class);
319
+ $ this ->expectExceptionMessage ('Too many authenticators were found for the current firewall "main". You must provide an instance of "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface" to login programmatically. The available authenticators for the firewall "main" are "security.authenticator.custom.main" ,"security.authenticator.other.main ' );
320
+ $ security ->login ($ user );
321
+ }
322
+
277
323
public function testLogout ()
278
324
{
279
325
$ request = new Request ();
0 commit comments