Add new class create methods for proper phpunit testing

instead of direct calling Client class and AWS class add a wrapper
method to call those so we can quicker replace under elements and also
do proper testing
This commit is contained in:
2022-06-10 14:40:40 +09:00
parent 6f177986f9
commit afb11a6797
2 changed files with 25 additions and 4 deletions

View File

@@ -129,6 +129,16 @@ class AWS
return new CreateBalanceResponse($result);
}
/**
* return a new curl connection client class
*
* @return Client Curl connection Client
*/
public function newClient(): Client
{
return new Client();
}
/**
* General request method for all actions
* Calls the Client class that actually runs the json request
@@ -190,7 +200,7 @@ class AWS
$date_time_string,
$service_target
);
return (new Client())->request($url, $headers, $payload);
return ($this->newClient())->request($url, $headers, $payload);
}
/**

View File

@@ -67,7 +67,7 @@ final class AmazonIncentives
*/
public function buyGiftCard(float $value, string $creation_request_id = null): Response\CreateResponse
{
return (new AWS($this->config))->getCode($value, $creation_request_id);
return ($this->newAWS())->getCode($value, $creation_request_id);
}
@@ -82,7 +82,7 @@ final class AmazonIncentives
*/
public function cancelGiftCard(string $creation_request_id, string $gift_card_id): Response\CancelResponse
{
return (new AWS($this->config))->cancelCode($creation_request_id, $gift_card_id);
return ($this->newAWS())->cancelCode($creation_request_id, $gift_card_id);
}
/**
@@ -94,7 +94,7 @@ final class AmazonIncentives
*/
public function getAvailableFunds(): Response\CreateBalanceResponse
{
return (new AWS($this->config))->getBalance();
return ($this->newAWS())->getBalance();
}
/**
@@ -119,6 +119,17 @@ final class AmazonIncentives
return new static($key, $secret, $partner, $endpoint, $currency, $debug);
}
/**
* wrapper to create new AWS class.
* used in all buy/cancel/get calss
*
* @return AWS Main AWS worker class
*/
public function newAWS(): AWS
{
return new AWS($this->config);
}
/**
* Decodes the Exception message body
* Returns an array with code (Amazon error codes), type (Amazon error info)