Improved ValidationException to avoid polluting the message with invalid data but keeping it on the string representation

This commit is contained in:
Alejandro Celaya
2019-11-21 20:05:06 +01:00
parent ad592a563c
commit 6ddb60d047
6 changed files with 55 additions and 53 deletions

View File

@@ -42,7 +42,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
}
/** @test */
public function errorResponseIsReturnedIfInvalidApiKeyIsProvided()
public function errorResponseIsReturnedIfInvalidApiKeyIsProvided(): void
{
$request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(false);
@@ -53,12 +53,12 @@ class SingleStepCreateShortUrlActionTest extends TestCase
$this->assertEquals(400, $resp->getStatusCode());
$this->assertEquals('INVALID_ARGUMENT', $payload['error']);
$this->assertEquals('No API key was provided or it is not valid', $payload['message']);
$this->assertEquals('Provided data is not valid', $payload['message']);
$findApiKey->shouldHaveBeenCalled();
}
/** @test */
public function errorResponseIsReturnedIfNoUrlIsProvided()
public function errorResponseIsReturnedIfNoUrlIsProvided(): void
{
$request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(true);
@@ -69,12 +69,12 @@ class SingleStepCreateShortUrlActionTest extends TestCase
$this->assertEquals(400, $resp->getStatusCode());
$this->assertEquals('INVALID_ARGUMENT', $payload['error']);
$this->assertEquals('A URL was not provided', $payload['message']);
$this->assertEquals('Provided data is not valid', $payload['message']);
$findApiKey->shouldHaveBeenCalled();
}
/** @test */
public function properDataIsPassedWhenGeneratingShortCode()
public function properDataIsPassedWhenGeneratingShortCode(): void
{
$request = (new ServerRequest())->withQueryParams([
'apiKey' => 'abc123',