1313use Symfony \Component \HttpFoundation \RedirectResponse ;
1414use Symfony \Component \HttpFoundation \Request ;
1515use Symfony \Component \HttpFoundation \Session \Flash \FlashBagInterface ;
16+ use Symfony \Component \HttpFoundation \Session \Session ;
1617use Symfony \Component \HttpFoundation \Session \SessionInterface ;
1718use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
1819use Symfony \Component \HttpKernel \HttpKernelInterface ;
@@ -23,13 +24,11 @@ class UnauthorizedSubscriberTest extends TestCase
2324{
2425 private UnauthorizedSubscriber $ subscriber ;
2526 private UrlGeneratorInterface &MockObject $ urlGenerator ;
26- private FlashBagInterface &MockObject $ flashBag ;
2727
2828 protected function setUp (): void
2929 {
3030 $ this ->urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
31- $ this ->flashBag = $ this ->createMock (FlashBagInterface::class);
32- $ this ->subscriber = new UnauthorizedSubscriber ($ this ->urlGenerator , $ this ->flashBag );
31+ $ this ->subscriber = new UnauthorizedSubscriber ($ this ->urlGenerator );
3332 }
3433
3534 public function testGetSubscribedEvents (): void
@@ -44,13 +43,15 @@ public function testOnKernelExceptionWithUnauthorizedException(): void
4443 {
4544 $ authException = new AuthenticationException ('Unauthorized ' );
4645
47- $ session = $ this ->createMock (SessionInterface::class);
48- $ session ->expects ($ this ->once ())->method ('invalidate ' );
49-
50- $ this ->flashBag ->expects ($ this ->once ())
46+ $ flashBag = $ this ->createMock (FlashBagInterface::class);
47+ $ flashBag ->expects ($ this ->once ())
5148 ->method ('add ' )
5249 ->with ('error ' , 'Your session has expired. Please log in again. ' );
5350
51+ $ session = $ this ->createMock (Session::class);
52+ $ session ->expects ($ this ->once ())->method ('invalidate ' );
53+ $ session ->method ('getFlashBag ' )->willReturn ($ flashBag );
54+
5455 $ request = $ this ->createMock (Request::class);
5556 $ request ->method ('hasSession ' )->willReturn (true );
5657 $ request ->method ('getSession ' )->willReturn ($ session );
0 commit comments