@@ -152,14 +152,67 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, ?
152152 /**
153153 * @dataProvider getAccessDeniedExceptionProvider
154154 */
155- public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrue (\Exception $ exception , ?\Exception $ eventException = null )
155+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrueNotAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
156156 {
157157 $ event = $ this ->createEvent ($ exception );
158158
159159 $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
160160 $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
161161
162- $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (false ));
162+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ,false ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (false ));
163+ $ listener ->onKernelException ($ event );
164+
165+ $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
166+ $ this ->assertSame ($ eventException ?? $ exception , $ event ->getThrowable ()->getPrevious ());
167+ }
168+
169+ /**
170+ * @dataProvider getAccessDeniedExceptionProvider
171+ */
172+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalseNotAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
173+ {
174+ $ event = $ this ->createEvent ($ exception );
175+
176+ $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
177+ $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
178+
179+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ,false ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (true ));
180+ $ listener ->onKernelException ($ event );
181+
182+ $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
183+ $ this ->assertSame ($ eventException ?? $ exception , $ event ->getThrowable ()->getPrevious ());
184+ }
185+
186+ /**
187+ * @dataProvider getAccessDeniedExceptionProvider
188+ */
189+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustomNotAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
190+ {
191+ $ event = $ this ->createEvent ($ exception );
192+
193+ $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
194+ $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
195+
196+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ,false ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (new Response ('Full Fledged Response ' , 401 )));
197+ $ listener ->onKernelException ($ event );
198+
199+ var_dump ($ event ->getResponse ());
200+
201+ $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
202+ $ this ->assertSame ($ eventException ?? $ exception , $ event ->getThrowable ()->getPrevious ());
203+ }
204+
205+ /**
206+ * @dataProvider getAccessDeniedExceptionProvider
207+ */
208+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrueAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
209+ {
210+ $ event = $ this ->createEvent ($ exception );
211+
212+ $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
213+ $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
214+
215+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ,true ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (false ));
163216 $ listener ->onKernelException ($ event );
164217
165218 $ this ->assertNull ($ event ->getResponse ());
@@ -169,14 +222,14 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrue(\
169222 /**
170223 * @dataProvider getAccessDeniedExceptionProvider
171224 */
172- public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalse (\Exception $ exception , ?\Exception $ eventException = null )
225+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalseAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
173226 {
174227 $ event = $ this ->createEvent ($ exception );
175228
176229 $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
177230 $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
178231
179- $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (true ));
232+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false , true ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (true ));
180233 $ listener ->onKernelException ($ event );
181234
182235 $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
@@ -186,14 +239,14 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalse(
186239 /**
187240 * @dataProvider getAccessDeniedExceptionProvider
188241 */
189- public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustom (\Exception $ exception , ?\Exception $ eventException = null )
242+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustomAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
190243 {
191244 $ event = $ this ->createEvent ($ exception );
192245
193246 $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
194247 $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
195248
196- $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (new Response ('Full Fledged Response ' , 401 )));
249+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false , true ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (new Response ('Full Fledged Response ' , 401 )));
197250 $ listener ->onKernelException ($ event );
198251
199252 $ this ->assertEquals ('Full Fledged Response ' , $ event ->getResponse ()->getContent ());
@@ -251,10 +304,11 @@ private function createEntryPointWithoutStartCalled()
251304 return $ entryPoint ;
252305 }
253306
254- private function createTrustResolver ($ fullFledged )
307+ private function createTrustResolver ($ fullFledged, $ authenticate = false )
255308 {
256309 $ trustResolver = $ this ->createMock (AuthenticationTrustResolverInterface::class);
257310 $ trustResolver ->expects ($ this ->once ())->method ('isFullFledged ' )->willReturn ($ fullFledged );
311+ $ trustResolver ->method ('isAuthenticated ' )->willReturn ($ authenticate );
258312
259313 return $ trustResolver ;
260314 }
@@ -285,7 +339,7 @@ private function createExceptionListener(?TokenStorageInterface $tokenStorage =
285339 private function createNotFullFledgedHandler (bool |Response $ response = false )
286340 {
287341 $ entryPoint = $ this ->createMock (NotFullFledgedHandlerInterface::class);
288- $ entryPoint ->expects ( $ this -> once ())-> method ('handle ' )->willReturn ($ response );
342+ $ entryPoint ->method ('handle ' )->willReturn ($ response );
289343
290344 return $ entryPoint ;
291345 }
0 commit comments