@@ -201,6 +201,28 @@ public function testLoginWithoutAuthenticatorThrows()
201201 $ security ->login ($ user );
202202 }
203203
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+
204226 public function testLogout ()
205227 {
206228 $ request = new Request ();
@@ -407,6 +429,27 @@ public function testLogoutWithValidCsrf()
407429 $ this ->assertEquals ('a custom response ' , $ response ->getContent ());
408430 }
409431
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+
410453 private function createContainer (string $ serviceId , object $ serviceObject ): ContainerInterface
411454 {
412455 return new ServiceLocator ([$ serviceId => fn () => $ serviceObject ]);
0 commit comments