From afb11a6797df11c43e7f606b19f8c010053e29b1 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 10 Jun 2022 14:40:40 +0900 Subject: [PATCH] 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 --- src/AWS/AWS.php | 12 +++++++++++- src/AmazonIncentives.php | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/AWS/AWS.php b/src/AWS/AWS.php index d890598..58d62fb 100644 --- a/src/AWS/AWS.php +++ b/src/AWS/AWS.php @@ -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); } /** diff --git a/src/AmazonIncentives.php b/src/AmazonIncentives.php index 989f2f2..ca8123b 100644 --- a/src/AmazonIncentives.php +++ b/src/AmazonIncentives.php @@ -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)