Refactored and fixed unit tests

This commit is contained in:
Alejandro Celaya
2019-11-26 22:12:52 +01:00
parent 5213faa0a1
commit 3b56fc3760
15 changed files with 11 additions and 171 deletions

View File

@@ -14,17 +14,10 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
{
use CommonProblemDetailsExceptionTrait;
/** @var string */
private $errorCode;
/** @var string */
private $publicMessage;
public static function forInvalidApiKey(): self
{
$e = new self('Provided API key does not exist or is invalid.');
$e->publicMessage = $e->getMessage();
$e->errorCode = 'INVALID_API_KEY';
$e->detail = $e->getMessage();
$e->title = 'Invalid API key';
$e->type = 'INVALID_API_KEY';
@@ -41,8 +34,6 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
. 'token on every new request on the Authorization header'
);
$e->publicMessage = $e->getMessage();
$e->errorCode = 'INVALID_AUTH_TOKEN';
$e->detail = $e->getMessage();
$e->title = 'Invalid auth token';
$e->type = 'INVALID_AUTH_TOKEN';
@@ -56,8 +47,6 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
{
$e = new self('You need to provide the Bearer type in the Authorization header.');
$e->publicMessage = $e->getMessage();
$e->errorCode = 'INVALID_AUTHORIZATION';
$e->detail = $e->getMessage();
$e->title = 'Invalid authorization';
$e->type = 'INVALID_AUTHORIZATION';
@@ -71,8 +60,6 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
{
$e = new self(sprintf('Provided authorization type %s is not supported. Use Bearer instead.', $providedType));
$e->publicMessage = $e->getMessage();
$e->errorCode = 'INVALID_AUTHORIZATION';
$e->detail = $e->getMessage();
$e->title = 'Invalid authorization';
$e->type = 'INVALID_AUTHORIZATION';
@@ -80,14 +67,4 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
return $e;
}
public function getErrorCode(): string
{
return $this->errorCode;
}
public function getPublicMessage(): string
{
return $this->publicMessage;
}
}