|
3 | 3 | use Illuminate\Http\Response;
|
4 | 4 | use Illuminate\Support\Facades\App;
|
5 | 5 | use Illuminate\Support\Facades\Route;
|
6 |
| -use KodePandai\ApiResponse\Exceptions\ApiException; |
7 |
| -use KodePandai\ApiResponse\Exceptions\ApiValidationException; |
8 | 6 | use KodePandai\ApiResponse\Tests\TestCase;
|
9 | 7 | use function Pest\Laravel\getJson;
|
10 | 8 |
|
11 |
| -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
12 |
| - |
13 | 9 | uses(TestCase::class);
|
14 | 10 |
|
15 | 11 | it('render an api response when exception is thrown', function () {
|
16 | 12 | //.
|
17 |
| - Route::get('error', fn () => throw new InvalidArgumentException('Hehehe')); |
| 13 | + Route::get('error', function () { |
| 14 | + throw new InvalidArgumentException('Hehehe'); |
| 15 | + }); |
18 | 16 |
|
19 | 17 | getJson('error')
|
20 | 18 | ->assertStatus(Response::HTTP_INTERNAL_SERVER_ERROR)
|
|
26 | 24 | it('does not display message and stack traces on production', function () {
|
27 | 25 | //.
|
28 | 26 | Route::get('error', function () {
|
29 |
| - App::detectEnvironment(fn () => 'production'); |
| 27 | + App::detectEnvironment(function () { |
| 28 | + return 'production'; |
| 29 | + }); |
30 | 30 |
|
31 | 31 | throw new InvalidArgumentException('Hihihi');
|
32 | 32 | });
|
|
49 | 49 |
|
50 | 50 | it('only display traces when response status code in [400, 502, 500]', function () {
|
51 | 51 | //.
|
52 |
| - Route::get('400', fn () => throw new ApiException()); |
53 |
| - Route::get('502', fn () => throw new ApiException(502, 502)); |
54 |
| - Route::get('500', fn () => throw new ApiException(500, 500)); |
55 |
| - Route::get('404', fn () => throw new NotFoundHttpException(404)); |
56 |
| - Route::get('422', fn () => throw new ApiValidationException()); |
| 52 | + Route::get('400', function () { |
| 53 | + return abort(Response::HTTP_BAD_REQUEST); |
| 54 | + }); |
| 55 | + Route::get('502', function () { |
| 56 | + return abort(Response::HTTP_BAD_GATEWAY); |
| 57 | + }); |
| 58 | + Route::get('500', function () { |
| 59 | + return abort(Response::HTTP_INTERNAL_SERVER_ERROR); |
| 60 | + }); |
| 61 | + Route::get('404', function () { |
| 62 | + return abort(Response::HTTP_NOT_FOUND); |
| 63 | + }); |
| 64 | + Route::get('422', function () { |
| 65 | + throw abort(Response::HTTP_UNPROCESSABLE_ENTITY); |
| 66 | + }); |
57 | 67 |
|
58 | 68 | getJson('400')
|
59 | 69 | ->assertStatus(Response::HTTP_BAD_REQUEST)
|
|
0 commit comments