Converted DeleteShortUrlException into a problem details exception

This commit is contained in:
Alejandro Celaya
2019-11-24 23:56:02 +01:00
parent 32b3c72bdf
commit 310032e303
5 changed files with 24 additions and 58 deletions

View File

@@ -7,12 +7,8 @@ namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Exception;
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Throwable;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequest;
class DeleteShortUrlActionTest extends TestCase
@@ -39,30 +35,4 @@ class DeleteShortUrlActionTest extends TestCase
$this->assertEquals(204, $resp->getStatusCode());
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
/**
* @test
* @dataProvider provideExceptions
*/
public function returnsErrorResponseInCaseOfException(Throwable $e, string $error, int $statusCode): void
{
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e);
/** @var JsonResponse $resp */
$resp = $this->action->handle(new ServerRequest());
$payload = $resp->getPayload();
$this->assertEquals($statusCode, $resp->getStatusCode());
$this->assertEquals($error, $payload['error']);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
public function provideExceptions(): iterable
{
yield 'bad request' => [
new Exception\DeleteShortUrlException(5),
RestUtils::INVALID_SHORTCODE_DELETION_ERROR,
400,
];
}
}