|
2 | 2 |
|
3 | 3 | namespace Dingo\Api\Tests; |
4 | 4 |
|
| 5 | +use Dingo\Api\Exception\ValidationHttpException; |
5 | 6 | use Mockery as m; |
6 | 7 | use Dingo\Api\Http; |
7 | 8 | use Dingo\Api\Auth\Auth; |
@@ -368,4 +369,46 @@ public function testUsingRequestFacadeDoesNotCacheRequestInstance() |
368 | 369 | $this->assertSame('bar', $response); |
369 | 370 | $this->assertNull(RequestFacade::input('foo')); |
370 | 371 | } |
| 372 | + |
| 373 | + public function testRedirectResponseThrowsException() |
| 374 | + { |
| 375 | + $this->router->version('v1', function () { |
| 376 | + $this->router->get('redirect', function () { |
| 377 | + return new \Illuminate\Http\RedirectResponse('redirect-test'); |
| 378 | + }); |
| 379 | + }); |
| 380 | + |
| 381 | + $response = $this->dispatcher->get('redirect'); |
| 382 | + $this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response); |
| 383 | + $this->assertSame('redirect-test', $response->getTargetUrl()); |
| 384 | + } |
| 385 | + |
| 386 | + /** |
| 387 | + * @expectedException \Dingo\Api\Exception\InternalHttpException |
| 388 | + */ |
| 389 | + public function testNotOkJsonResponseThrowsException() |
| 390 | + { |
| 391 | + $this->router->version('v1', function () { |
| 392 | + $this->router->get('json', function () { |
| 393 | + return new \Illuminate\Http\JsonResponse(['is' => 'json'], 422); |
| 394 | + }); |
| 395 | + }); |
| 396 | + |
| 397 | + $this->dispatcher->get('json'); |
| 398 | + } |
| 399 | + |
| 400 | + /** |
| 401 | + * @expectedException \Dingo\Api\Exception\ValidationHttpException |
| 402 | + */ |
| 403 | + public function testFormRequestValidationFailureThrowsValidationException() |
| 404 | + { |
| 405 | + $this->router->version('v1', function () { |
| 406 | + $this->router->get('fail', function () { |
| 407 | + //Mocking the form validation call is challenging at the moment, so next best thing |
| 408 | + throw new ValidationHttpException(['foo' => 'bar']); |
| 409 | + }); |
| 410 | + }); |
| 411 | + |
| 412 | + $this->dispatcher->get('fail'); |
| 413 | + } |
371 | 414 | } |
0 commit comments