Skip to content

Commit

Permalink
Change the naming of the response exceptions pool into factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Benedetti committed Sep 11, 2020
1 parent 1689b7a commit 0e23541
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DoclerLabs\ApiClientBase\Exception;

class ResponseExceptionsPool
class ResponseExceptionFactory
{
/** @var string[] */
private $responseExceptions;
Expand All @@ -18,7 +18,7 @@ public function __construct()
];
}

public function getException(int $statusCode, string $responseBody): UnexpectedResponseException
public function create(int $statusCode, string $responseBody): UnexpectedResponseException
{
if (isset($this->responseExceptions[$statusCode])) {
return new $this->responseExceptions[$statusCode]($responseBody);
Expand Down
10 changes: 5 additions & 5 deletions src/Response/Handler/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use DoclerLabs\ApiClientBase\Exception\ForbiddenResponseException;
use DoclerLabs\ApiClientBase\Exception\NotFoundResponseException;
use DoclerLabs\ApiClientBase\Exception\PaymentRequiredResponseException;
use DoclerLabs\ApiClientBase\Exception\ResponseExceptionsPool;
use DoclerLabs\ApiClientBase\Exception\ResponseExceptionFactory;
use DoclerLabs\ApiClientBase\Exception\UnauthorizedResponseException;
use DoclerLabs\ApiClientBase\Exception\UnexpectedResponseException;
use DoclerLabs\ApiClientBase\Json\Json;
Expand All @@ -19,12 +19,12 @@ class ResponseHandler implements ResponseHandlerInterface
{
const JSON_OPTIONS = JSON_PRESERVE_ZERO_FRACTION + JSON_BIGINT_AS_STRING;

/** @var ResponseExceptionsPool */
private $responseExceptionsPool;
/** @var ResponseExceptionFactory */
private $responseExceptionsFactory;

public function __construct()
{
$this->responseExceptionsPool = new ResponseExceptionsPool();
$this->responseExceptionsFactory = new ResponseExceptionFactory();
}

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public function handle(ResponseInterface $response): Response
return new Response($statusCode, $decodedPayload, $headers);
}

throw $this->responseExceptionsPool->getException($statusCode, $responseBody);
throw $this->responseExceptionsFactory->create($statusCode, $responseBody);
}

private function isResponseBodyEmpty(StreamInterface $responseBody = null): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
use DoclerLabs\ApiClientBase\Exception\ForbiddenResponseException;
use DoclerLabs\ApiClientBase\Exception\NotFoundResponseException;
use DoclerLabs\ApiClientBase\Exception\PaymentRequiredResponseException;
use DoclerLabs\ApiClientBase\Exception\ResponseExceptionsPool;
use DoclerLabs\ApiClientBase\Exception\ResponseExceptionFactory;
use DoclerLabs\ApiClientBase\Exception\UnauthorizedResponseException;
use DoclerLabs\ApiClientBase\Exception\UnexpectedResponseException;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DoclerLabs\ApiClientBase\Exception\ResponseExceptionsPool
* @coversDefaultClass \DoclerLabs\ApiClientBase\Exception\ResponseExceptionFactory
*/
class ResponseExceptionsPoolTest extends TestCase
class ResponseExceptionsFactoryTest extends TestCase
{
/**
* @dataProvider exceptionsDataProvider
* @covers ::__construct
* @covers ::getException
* @covers ::create
*/
public function testGetException(int $statusCode, string $body, string $expectedExceptionClass)
public function testCreate(int $statusCode, string $body, string $expectedExceptionClass)
{
$sut = new ResponseExceptionsPool();
$sut = new ResponseExceptionFactory();

$this->expectException($expectedExceptionClass);

throw $sut->getException($statusCode, $body);
throw $sut->create($statusCode, $body);
}

public function exceptionsDataProvider(): array
Expand Down

0 comments on commit 0e23541

Please sign in to comment.