@@ -107,6 +107,20 @@ public function testHandlerCallsReportMethodWithDependencies()
107
107
$ this ->handler ->report (new ReportableException ('Exception message ' ));
108
108
}
109
109
110
+ public function testHandlerReportsExceptionUsingCallableClass ()
111
+ {
112
+ $ reporter = m::mock (ReportingService::class);
113
+ $ reporter ->shouldReceive ('send ' )->withArgs (['Exception message ' ])->once ();
114
+
115
+ $ logger = m::mock (LoggerInterface::class);
116
+ $ this ->container ->instance (LoggerInterface::class, $ logger );
117
+ $ logger ->shouldNotReceive ('error ' );
118
+
119
+ $ this ->handler ->reportable (new CustomReporter ($ reporter ));
120
+
121
+ $ this ->handler ->report (new CustomException ('Exception message ' ));
122
+ }
123
+
110
124
public function testReturnsJsonWithStackTraceWhenAjaxRequestAndDebugTrue ()
111
125
{
112
126
$ this ->config ->shouldReceive ('get ' )->with ('app.debug ' , null )->once ()->andReturn (true );
@@ -134,6 +148,15 @@ public function testReturnsCustomResponseFromRenderableCallback()
134
148
$ this ->assertSame ('{"response":"My custom exception response"} ' , $ response );
135
149
}
136
150
151
+ public function testReturnsCustomResponseFromCallableClass ()
152
+ {
153
+ $ this ->handler ->renderable (new CustomRenderer ());
154
+
155
+ $ response = $ this ->handler ->render ($ this ->request , new CustomException )->getContent ();
156
+
157
+ $ this ->assertSame ('{"response":"The CustomRenderer response"} ' , $ response );
158
+ }
159
+
137
160
public function testReturnsCustomResponseWhenExceptionImplementsResponsable ()
138
161
{
139
162
$ response = $ this ->handler ->render ($ this ->request , new ResponsableException )->getContent ();
@@ -302,6 +325,31 @@ public function context()
302
325
}
303
326
}
304
327
328
+ class CustomReporter
329
+ {
330
+ private $ service ;
331
+
332
+ public function __construct (ReportingService $ service )
333
+ {
334
+ $ this ->service = $ service ;
335
+ }
336
+
337
+ public function __invoke (CustomException $ e )
338
+ {
339
+ $ this ->service ->send ($ e ->getMessage ());
340
+
341
+ return false ;
342
+ }
343
+ }
344
+
345
+ class CustomRenderer
346
+ {
347
+ public function __invoke (CustomException $ e , $ request )
348
+ {
349
+ return response ()->json (['response ' => 'The CustomRenderer response ' ]);
350
+ }
351
+ }
352
+
305
353
interface ReportingService
306
354
{
307
355
public function send ($ message );
0 commit comments