@@ -152,14 +152,65 @@ 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+ $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
200+ $ this ->assertSame ($ eventException ?? $ exception , $ event ->getThrowable ()->getPrevious ());
201+ }
202+
203+ /**
204+ * @dataProvider getAccessDeniedExceptionProvider
205+ */
206+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrueAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
207+ {
208+ $ event = $ this ->createEvent ($ exception );
209+
210+ $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
211+ $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
212+
213+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ,true ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (false ));
163214 $ listener ->onKernelException ($ event );
164215
165216 $ this ->assertNull ($ event ->getResponse ());
@@ -169,14 +220,14 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseTrue(\
169220 /**
170221 * @dataProvider getAccessDeniedExceptionProvider
171222 */
172- public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalse (\Exception $ exception , ?\Exception $ eventException = null )
223+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalseAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
173224 {
174225 $ event = $ this ->createEvent ($ exception );
175226
176227 $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);<
1E01
/div>
177228 $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
178229
179- $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (true ));
230+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false , true ), null , $ this ->createEntryPoint (), null , null , $ this ->createNotFullFledgedHandler (true ));
180231 $ listener ->onKernelException ($ event );
181232
182233 $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
@@ -186,14 +237,14 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseFalse(
186237 /**
187238 * @dataProvider getAccessDeniedExceptionProvider
188239 */
189- public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustom (\Exception $ exception , ?\Exception $ eventException = null )
240+ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustomAuthenticated (\Exception $ exception , ?\Exception $ eventException = null )
190241 {
191242 $ event = $ this ->createEvent ($ exception );
192243
193244 $ tokenStorage = $ this ->createMock (TokenStorageInterface::class);
194245 $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->willReturn ($ this ->createMock (TokenInterface::class));
195246
196- $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (new Response ('Full Fledged Response ' , 401 )));
247+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false , true ), null , $ this ->createEntryPointWithoutStartCalled (), null , null , $ this ->createNotFullFledgedHandler (new Response ('Full Fledged Response ' , 401 )));
197248 $ listener ->onKernelException ($ event );
198249
199250 $ this ->assertEquals ('Full Fledged Response ' , $ event ->getResponse ()->getContent ());
@@ -251,10 +302,11 @@ private function createEntryPointWithoutStartCalled()
251302 return $ entryPoint ;
252303 }
253304
254- private function createTrustResolver ($ fullFledged )
305+ private function createTrustResolver ($ fullFledged, $ authenticate = false )
255306 {
256307 $ trustResolver = $ this ->createMock (AuthenticationTrustResolverInterface::class);
257308 $ trustResolver ->expects ($ this ->once ())->method ('isFullFledged ' )->willReturn ($ fullFledged );
309+ $ trustResolver ->method ('isAuthenticated ' )->willReturn ($ authenticate );
258310
259311 return $ trustResolver ;
260312 }
@@ -285,7 +337,7 @@ private function createExceptionListener(?TokenStorageInterface $tokenStorage =
285337 private function createNotFullFledgedHandler (bool |Response $ response = false )
286338 {
287339 $ entryPoint = $ this ->createMock (NotFullFledgedHandlerInterface::class);
288- $ entryPoint ->expects ( $ this -> once ())-> method ('handle ' )->willReturn ($ response );
340+ $ entryPoint ->method ('handle ' )->willReturn ($ response );
289341
290342 return $ entryPoint ;
291343 }
0 commit comments