@@ -201,6 +201,28 @@ public function testLoginWithoutAuthenticatorThrows()
201
201
$ security ->login ($ user );
202
202
}
203
203
204
+ public function testLoginWithoutRequestContext ()
205
+ {
206
+ $ requestStack = new RequestStack ();
207
+ $ user = $ this ->createMock (UserInterface::class);
208
+
209
+ $ container = $ this ->createMock (ContainerInterface::class);
210
+ $ container
211
+ ->expects ($ this ->atLeastOnce ())
212
+ ->method ('get ' )
213
+ ->willReturnMap ([
214
+ ['request_stack ' , $ requestStack ],
215
+ ])
216
+ ;
217
+
218
+ $ security = new Security ($ container , ['main ' => null ]);
219
+
220
+ $ this ->expectException (\LogicException::class);
221
+ $ this ->expectExceptionMessage ('Unable to login without a request context. ' );
222
+
223
+ $ security ->login ($ user );
224
+ }
225
+
204
226
public function testLogout ()
205
227
{
206
228
$ request = new Request ();
@@ -407,6 +429,27 @@ public function testLogoutWithValidCsrf()
407
429
$ this ->assertEquals ('a custom response ' , $ response ->getContent ());
408
430
}
409
431
432
+ public function testLogoutWithoutRequestContext ()
433
+ {
434
+ $ requestStack = new RequestStack ();
435
+
436
+ $ container = $ this ->createMock (ContainerInterface::class);
437
+ $ container
438
+ ->expects ($ this ->atLeastOnce ())
439
+ ->method ('get ' )
440
+ ->willReturnMap ([
441
+ ['request_stack ' , $ requestStack ],
442
+ ])
443
+ ;
444
+
445
+ $ security = new Security ($ container , ['main ' => null ]);
446
+
447
+ $ this ->expectException (\LogicException::class);
448
+ $ this ->expectExceptionMessage ('Unable to logout without a request context. ' );
449
+
450
+ $ security ->logout ();
451
+ }
452
+
410
453
private function createContainer (string $ serviceId , object $ serviceObject ): ContainerInterface
411
454
{
412
455
return new ServiceLocator ([$ serviceId => fn () => $ serviceObject ]);
0 commit comments