Converted ValidationException into a problem details exception

This commit is contained in:
Alejandro Celaya
2019-11-24 23:45:40 +01:00
parent c1eee2246b
commit 32b3c72bdf
8 changed files with 47 additions and 78 deletions

View File

@@ -10,11 +10,11 @@ use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\UriInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequest;
class SingleStepCreateShortUrlActionTest extends TestCase
@@ -47,14 +47,10 @@ class SingleStepCreateShortUrlActionTest extends TestCase
$request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(false);
/** @var JsonResponse $resp */
$resp = $this->action->handle($request);
$payload = $resp->getPayload();
$this->expectException(ValidationException::class);
$findApiKey->shouldBeCalledOnce();
$this->assertEquals(400, $resp->getStatusCode());
$this->assertEquals('INVALID_ARGUMENT', $payload['error']);
$this->assertEquals('Provided data is not valid', $payload['message']);
$findApiKey->shouldHaveBeenCalled();
$this->action->handle($request);
}
/** @test */
@@ -63,14 +59,10 @@ class SingleStepCreateShortUrlActionTest extends TestCase
$request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(true);
/** @var JsonResponse $resp */
$resp = $this->action->handle($request);
$payload = $resp->getPayload();
$this->expectException(ValidationException::class);
$findApiKey->shouldBeCalledOnce();
$this->assertEquals(400, $resp->getStatusCode());
$this->assertEquals('INVALID_ARGUMENT', $payload['error']);
$this->assertEquals('Provided data is not valid', $payload['message']);
$findApiKey->shouldHaveBeenCalled();
$this->action->handle($request);
}
/** @test */