@@ -111,13 +111,26 @@ public function testReturnsJsonWithStackTraceWhenAjaxRequestAndDebugTrue()
111111 $ this ->assertStringContainsString ('"trace": ' , $ response );
112112 }
113113
114- public function testReturnsCustomResponseWhenExceptionImplementsResponsable ()
114+ public function testReturnsCustomResponseFromRenderableCallback ()
115115 {
116+ $ this ->handler ->renderable (function (CustomException $ e , $ request ) {
117+ $ this ->assertSame ($ this ->request , $ request );
118+
119+ return response ()->json (['response ' => 'My custom exception response ' ]);
120+ });
121+
116122 $ response = $ this ->handler ->render ($ this ->request , new CustomException )->getContent ();
117123
118124 $ this ->assertSame ('{"response":"My custom exception response"} ' , $ response );
119125 }
120126
127+ public function testReturnsCustomResponseWhenExceptionImplementsResponsable ()
128+ {
129+ $ response = $ this ->handler ->render ($ this ->request , new ResponsableException )->getContent ();
130+
131+ $ this ->assertSame ('{"response":"My responsable exception response"} ' , $ response );
132+ }
133+
121134 public function testReturnsJsonWithoutStackTraceWhenAjaxRequestAndDebugFalseAndExceptionMessageIsMasked ()
122135 {
123136 $ this ->config ->shouldReceive ('get ' )->with ('app.debug ' , null )->once ()->andReturn (false );
@@ -224,11 +237,15 @@ public function testSuspiciousOperationReturns404WithoutReporting()
224237 }
225238}
226239
227- class CustomException extends Exception implements Responsable
240+ class CustomException extends Exception
241+ {
242+ }
243+
244+ class ResponsableException extends Exception implements Responsable
228245{
229246 public function toResponse ($ request )
230247 {
231- return response ()->json (['response ' => 'My custom exception response ' ]);
248+ return response ()->json (['response ' => 'My responsable exception response ' ]);
232249 }
233250}
234251
0 commit comments