Skip to content

Commit

Permalink
Added unit tests for RequestConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
DF-Dave committed Jul 22, 2024
1 parent 514bb0c commit 2f9f281
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/SaferpayJson/Tests/Request/CommonRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
use InvalidArgumentException;
use JMS\Serializer\SerializerBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -30,6 +31,36 @@ public function testErrorResponse(): void
$this->executeRequest();
}

public function getRequestConfigValidationParams(): array
{
return [
'first try' => [null, RequestConfig::MIN_RETRY_INDICATOR],
'second try' => [uniqid(), RequestConfig::MIN_RETRY_INDICATOR + 1],
'last try' => [uniqid(), RequestConfig::MAX_RETRY_INDICATOR],
'try after all retries exceeded' => [uniqid(), RequestConfig::MAX_RETRY_INDICATOR + 1, InvalidArgumentException::class],
'retry without previous request id' => [null, RequestConfig::MAX_RETRY_INDICATOR, InvalidArgumentException::class],
];
}

public function testRequestConfigValidation(
?string $requestId,
int $retryIndicator,
?string $expectedException = null): void
{
if ($expectedException !== null) {
$this->expectException($expectedException, $requestId, $retryIndicator);
}

new RequestConfig(
'apiKey',
'apiSecret',
'customerId',
false,
$requestId,
$retryIndicator
);
}

public function doTestSuccessfulResponse(string $responseClass): void
{
$this->successful = true;
Expand Down Expand Up @@ -87,7 +118,7 @@ private function getResponseMock(): MockObject

$response->expects($this->any())
->method('getStatusCode')
->will($this->returnValue($this->successful ? 200: 404));
->will($this->returnValue($this->successful ? 200 : 404));

if ($this->successful) {
$content = $this->getFakedApiResponse($this->successfulResponseClass);
Expand Down

0 comments on commit 2f9f281

Please sign in to comment.