|
18 | 18 | namespace CloudCreativity\LaravelJsonApi\Tests\Integration; |
19 | 19 |
|
20 | 20 | use Carbon\Carbon; |
| 21 | +use CloudCreativity\LaravelJsonApi\Document\Error\Error; |
21 | 22 | use CloudCreativity\LaravelJsonApi\Exceptions\DocumentRequiredException; |
22 | 23 | use CloudCreativity\LaravelJsonApi\Exceptions\InvalidJsonException; |
| 24 | +use CloudCreativity\LaravelJsonApi\Exceptions\JsonApiException; |
23 | 25 | use CloudCreativity\LaravelJsonApi\Exceptions\ResourceNotFoundException; |
24 | 26 | use DummyApp\Post; |
25 | 27 | use Illuminate\Contracts\Validation\Validator; |
|
28 | 30 | use Illuminate\Support\Facades\Route; |
29 | 31 | use Illuminate\Support\MessageBag; |
30 | 32 | use Illuminate\Validation\ValidationException; |
31 | | -use Neomerx\JsonApi\Document\Error; |
32 | | -use Neomerx\JsonApi\Exceptions\JsonApiException; |
| 33 | +use Neomerx\JsonApi\Document\Error as NeomerxError; |
| 34 | +use Neomerx\JsonApi\Exceptions\JsonApiException as NeomerxException; |
33 | 35 | use Symfony\Component\HttpKernel\Exception\HttpException; |
34 | 36 |
|
35 | 37 | class ErrorsTest extends TestCase |
@@ -239,19 +241,51 @@ public function testAcceptAny() |
239 | 241 | * |
240 | 242 | * @see https://github.com/cloudcreativity/laravel-json-api/issues/329 |
241 | 243 | */ |
242 | | - public function testUnexpectedJsonApiException() |
| 244 | + public function testNeomerxJsonApiException() |
243 | 245 | { |
244 | 246 | config()->set('app.debug', true); |
245 | 247 |
|
246 | 248 | Route::get('/test', function () { |
247 | | - throw new JsonApiException(new Error(null, null, 422, null, null, 'My foobar error message.'), 418); |
| 249 | + throw new NeomerxException(new NeomerxError( |
| 250 | + null, |
| 251 | + null, |
| 252 | + 422, |
| 253 | + null, |
| 254 | + null, |
| 255 | + 'My foobar error message.' |
| 256 | + ), 418); |
248 | 257 | }); |
249 | 258 |
|
250 | 259 | $this->get('/test', ['Accept' => '*/*']) |
251 | 260 | ->assertStatus(418) |
252 | 261 | ->assertSee('My foobar error message.'); |
253 | 262 | } |
254 | 263 |
|
| 264 | + public function testJsonApiException(): void |
| 265 | + { |
| 266 | + Route::get('/test', function () { |
| 267 | + throw JsonApiException::make(Error::fromArray([ |
| 268 | + 'status' => '418', |
| 269 | + 'detail' => "Hello, I'm a teapot.", |
| 270 | + ]))->withHeaders(['X-Foo' => 'Bar']); |
| 271 | + }); |
| 272 | + |
| 273 | + $expected = [ |
| 274 | + 'errors' => [ |
| 275 | + [ |
| 276 | + 'status' => '418', |
| 277 | + 'detail' => "Hello, I'm a teapot.", |
| 278 | + ], |
| 279 | + ], |
| 280 | + ]; |
| 281 | + |
| 282 | + $this->get('/test') |
| 283 | + ->assertStatus(418) |
| 284 | + ->assertHeader('Content-Type', 'application/vnd.api+json') |
| 285 | + ->assertHeader('X-Foo', 'Bar') |
| 286 | + ->assertExactJson($expected); |
| 287 | + } |
| 288 | + |
255 | 289 | public function testMaintenanceMode() |
256 | 290 | { |
257 | 291 | $ex = new MaintenanceModeException(Carbon::now()->getTimestamp(), 60, "We'll be back soon."); |
|
0 commit comments