From fedec3f2aa001f9c115606248dc2bc15f6c106a7 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Tue, 1 Oct 2024 16:39:50 -0300 Subject: [PATCH 01/11] refactor: remove imports used just for docs --- src/Contracts/HttpClientInterface.php | 3 +-- src/Contracts/RequestService.php | 3 +-- src/PatpassComercio/Inscription.php | 5 ++--- src/Utils/HttpClientRequestService.php | 4 ++-- src/Utils/RequestServiceTrait.php | 3 +-- src/Webpay/Oneclick/MallInscription.php | 7 +++---- src/Webpay/Oneclick/MallTransaction.php | 9 ++++----- src/Webpay/TransaccionCompleta/MallTransaction.php | 3 +-- src/Webpay/TransaccionCompleta/Transaction.php | 13 ++++++------- src/Webpay/WebpayPlus/MallTransaction.php | 13 +++++-------- src/Webpay/WebpayPlus/Transaction.php | 11 +++++------ 11 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/Contracts/HttpClientInterface.php b/src/Contracts/HttpClientInterface.php index 8e0cc63f..09847ef8 100644 --- a/src/Contracts/HttpClientInterface.php +++ b/src/Contracts/HttpClientInterface.php @@ -3,7 +3,6 @@ namespace Transbank\Contracts; use Psr\Http\Message\ResponseInterface; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; interface HttpClientInterface { @@ -13,7 +12,7 @@ interface HttpClientInterface * @param array|null $payload * @param array|null $options * - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return ResponseInterface */ diff --git a/src/Contracts/RequestService.php b/src/Contracts/RequestService.php index bdb57f0e..0a7097bd 100644 --- a/src/Contracts/RequestService.php +++ b/src/Contracts/RequestService.php @@ -3,7 +3,6 @@ namespace Transbank\Contracts; use Transbank\Webpay\Options; -use Transbank\Webpay\Exceptions\WebpayRequestException; use Psr\Http\Message\ResponseInterface; use Transbank\Utils\TransbankApiRequest; @@ -15,7 +14,7 @@ interface RequestService * @param array $payload * @param Options $options * - * @throws WebpayRequestException + * @throws \Transbank\Webpay\Exceptions\WebpayRequestException * * @return array Response from the API as json. */ diff --git a/src/PatpassComercio/Inscription.php b/src/PatpassComercio/Inscription.php index 0973db44..053a49d0 100644 --- a/src/PatpassComercio/Inscription.php +++ b/src/PatpassComercio/Inscription.php @@ -17,7 +17,6 @@ use Transbank\Utils\RequestServiceTrait; use Transbank\Contracts\RequestService; use Transbank\PatpassComercio\Options; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; class Inscription { @@ -63,7 +62,7 @@ public function __construct( * @param string $city * * @throws InscriptionStartException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return InscriptionStartResponse */ @@ -123,7 +122,7 @@ public function start( * @param string $token * * @throws InscriptionStatusException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return InscriptionStatusResponse */ diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index 2c896af7..f04a9c2c 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -8,7 +8,6 @@ use Transbank\Utils\Curl\HttpCurlClient; use Transbank\Webpay\Exceptions\WebpayRequestException; use Transbank\Webpay\Options; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; use Psr\Http\Message\ResponseInterface; class HttpClientRequestService implements RequestService @@ -57,7 +56,8 @@ public function setHttpClient(HttpClientInterface $httpClient): void * @param array $payload * @param Options $options * - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException + * @throws WebpayRequestException * * @return array diff --git a/src/Utils/RequestServiceTrait.php b/src/Utils/RequestServiceTrait.php index a58bb488..c34e94f9 100644 --- a/src/Utils/RequestServiceTrait.php +++ b/src/Utils/RequestServiceTrait.php @@ -3,7 +3,6 @@ namespace Transbank\Utils; use Transbank\Contracts\RequestService; -use Transbank\Webpay\Exceptions\WebpayRequestException; /** * Trait RequestServiceTrait . @@ -21,7 +20,7 @@ trait RequestServiceTrait * @param string $endpoint * @param array $payload * - * @throws WebpayRequestException + * @throws \Transbank\Webpay\Exceptions\WebpayRequestException * * @return array */ diff --git a/src/Webpay/Oneclick/MallInscription.php b/src/Webpay/Oneclick/MallInscription.php index a69533e5..30f3af15 100644 --- a/src/Webpay/Oneclick/MallInscription.php +++ b/src/Webpay/Oneclick/MallInscription.php @@ -10,7 +10,6 @@ use Transbank\Webpay\Oneclick\Responses\InscriptionDeleteResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionFinishResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionStartResponse; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; class MallInscription { @@ -28,7 +27,7 @@ class MallInscription * @return InscriptionStartResponse * * @throws InscriptionStartException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function start(string $username, string $email, string $responseUrl): InscriptionStartResponse { @@ -63,7 +62,7 @@ public function start(string $username, string $email, string $responseUrl): Ins * @return InscriptionFinishResponse * * @throws InscriptionFinishException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function finish(string $token): InscriptionFinishResponse { @@ -93,7 +92,7 @@ public function finish(string $token): InscriptionFinishResponse * @return InscriptionDeleteResponse * * @throws InscriptionDeleteException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function delete(string $tbkUser, string $username): InscriptionDeleteResponse { diff --git a/src/Webpay/Oneclick/MallTransaction.php b/src/Webpay/Oneclick/MallTransaction.php index 51a8734c..3a57d317 100644 --- a/src/Webpay/Oneclick/MallTransaction.php +++ b/src/Webpay/Oneclick/MallTransaction.php @@ -12,7 +12,6 @@ use Transbank\Webpay\Oneclick\Responses\MallTransactionCaptureResponse; use Transbank\Webpay\Oneclick\Responses\MallTransactionRefundResponse; use Transbank\Webpay\Oneclick\Responses\MallTransactionStatusResponse; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; class MallTransaction { @@ -31,7 +30,7 @@ class MallTransaction * @return MallTransactionAuthorizeResponse * * @throws MallTransactionAuthorizeException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function authorize( string $userName, @@ -74,7 +73,7 @@ public function authorize( * @return MallTransactionCaptureResponse * * @throws MallTransactionCaptureException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function capture( string $childCommerceCode, @@ -114,7 +113,7 @@ public function capture( * @return MallTransactionStatusResponse * * @throws MallTransactionStatusException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function status(string $buyOrder): MallTransactionStatusResponse { @@ -146,7 +145,7 @@ public function status(string $buyOrder): MallTransactionStatusResponse * @return MallTransactionRefundResponse * * @throws MallRefundTransactionException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ public function refund( string $buyOrder, diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index f17b2508..26f95d25 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -21,7 +21,6 @@ use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionStatusResponse; use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionCaptureResponse; use Transbank\Utils\InteractsWithWebpayApi; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; use Transbank\Webpay\Exceptions\WebpayRequestException; class MallTransaction @@ -224,7 +223,7 @@ public function status(string $token) * @param int|float $captureAmount * * @throws MallTransactionCaptureException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionCaptureResponse */ diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index 6d27ef59..5b399e6a 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -16,7 +16,6 @@ use Transbank\Webpay\TransaccionCompleta\Responses\TransactionCaptureResponse; use Transbank\Utils\InteractsWithWebpayApi; use Transbank\Webpay\Exceptions\WebpayRequestException; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; /** * Class Transaction. @@ -42,7 +41,7 @@ class Transaction * @param string|null $cvv * * @throws TransactionCreateException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCreateResponse */ @@ -83,7 +82,7 @@ public function create( * @param int $installmentsNumber * * @throws TransactionInstallmentsException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionInstallmentsResponse */ @@ -119,7 +118,7 @@ public function installments( * @param bool|null $gracePeriod * * @throws TransactionCommitException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCommitResponse */ @@ -157,7 +156,7 @@ public function commit( * @param int|float $amount * * @throws TransactionRefundException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionRefundResponse */ @@ -188,7 +187,7 @@ public function refund(string $token, int|float $amount) * @param string $token * * @throws TransactionStatusException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionStatusResponse */ @@ -218,7 +217,7 @@ public function status($token) * @param int|float $captureAmount * * @throws TransactionCaptureException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCaptureResponse */ diff --git a/src/Webpay/WebpayPlus/MallTransaction.php b/src/Webpay/WebpayPlus/MallTransaction.php index 8f20dd8f..b9b21ac4 100644 --- a/src/Webpay/WebpayPlus/MallTransaction.php +++ b/src/Webpay/WebpayPlus/MallTransaction.php @@ -4,8 +4,6 @@ use Transbank\Utils\InteractsWithWebpayApi; use Transbank\Webpay\Exceptions\WebpayRequestException; -use Transbank\Webpay\Options; -use Transbank\Webpay\WebpayPlus; use Transbank\Webpay\WebpayPlus\Exceptions\MallTransactionCaptureException; use Transbank\Webpay\WebpayPlus\Exceptions\MallTransactionCommitException; use Transbank\Webpay\WebpayPlus\Exceptions\MallTransactionCreateException; @@ -16,7 +14,6 @@ use Transbank\Webpay\WebpayPlus\Responses\MallTransactionCreateResponse; use Transbank\Webpay\WebpayPlus\Responses\MallTransactionRefundResponse; use Transbank\Webpay\WebpayPlus\Responses\MallTransactionStatusResponse; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; class MallTransaction { @@ -36,7 +33,7 @@ class MallTransaction * @param array $details * * @throws MallTransactionCreateException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionCreateResponse */ @@ -72,7 +69,7 @@ public function create(string $buyOrder, string $sessionId, string $returnUrl, a * @param string $token * * @throws MallTransactionCommitException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionCommitResponse */ @@ -108,7 +105,7 @@ public function commit(string $token) * @param int|float $amount * * @throws MallTransactionRefundException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionRefundResponse */ @@ -143,7 +140,7 @@ public function refund(string $token, string $buyOrder, string $childCommerceCod * @param string $token * * @throws MallTransactionStatusException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionStatusResponse */ @@ -176,7 +173,7 @@ public function status(string $token) * @param int|float $captureAmount * * @throws MallTransactionCaptureException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return MallTransactionCaptureResponse */ diff --git a/src/Webpay/WebpayPlus/Transaction.php b/src/Webpay/WebpayPlus/Transaction.php index f4d0db6c..e6679e78 100644 --- a/src/Webpay/WebpayPlus/Transaction.php +++ b/src/Webpay/WebpayPlus/Transaction.php @@ -3,7 +3,6 @@ namespace Transbank\Webpay\WebpayPlus; use Transbank\Utils\InteractsWithWebpayApi; -use Transbank\Utils\Curl\Exceptions\CurlRequestException; use Transbank\Webpay\Exceptions\WebpayRequestException; use Transbank\Webpay\WebpayPlus\Exceptions\TransactionCaptureException; use Transbank\Webpay\WebpayPlus\Exceptions\TransactionCommitException; @@ -43,7 +42,7 @@ class Transaction * @param string $returnUrl * * @throws TransactionCreateException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCreateResponse */ @@ -79,7 +78,7 @@ public function create( * @param string $token * * @throws TransactionCommitException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCommitResponse */ @@ -113,7 +112,7 @@ public function commit(string $token): TransactionCommitResponse * @param int|float $amount * * @throws TransactionRefundException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionRefundResponse */ @@ -142,7 +141,7 @@ public function refund(string $token, int|float $amount): TransactionRefundRespo * @param string $token * * @throws TransactionStatusException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionStatusResponse */ @@ -174,7 +173,7 @@ public function status(string $token): TransactionStatusResponse * @param int|float $captureAmount * * @throws TransactionCaptureException - * @throws CurlRequestException + * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException * * @return TransactionCaptureResponse */ From c15180fb5a05bd635c58d34a803fd3ef0f383aa3 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Wed, 2 Oct 2024 12:41:29 -0300 Subject: [PATCH 02/11] feat: add create body method on message trait --- src/Utils/Curl/MessageTrait.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Utils/Curl/MessageTrait.php b/src/Utils/Curl/MessageTrait.php index bb137204..63b5a6ba 100644 --- a/src/Utils/Curl/MessageTrait.php +++ b/src/Utils/Curl/MessageTrait.php @@ -3,6 +3,7 @@ namespace Transbank\Utils\Curl; use Psr\Http\Message\StreamInterface; +use Transbank\Utils\Curl\Exceptions\CurlRequestException; trait MessageTrait { @@ -60,4 +61,21 @@ public function withBody(StreamInterface $body): static $new->body = $body; return $new; } + + private function createBody($body = ''): StreamInterface + { + $resource = fopen('php://temp', 'rw+'); + if ($resource === false) { + throw new CurlRequestException('Unable to open stream'); + } + + if (!empty($body)) { + $writtenBytes = fwrite($resource, $body); + if ($writtenBytes === false) { + throw new CurlRequestException('Unable to write to stream'); + } + } + + return new Stream($resource); + } } From 91eea175b4d5b1218be6d42ce1527b03ebd5d30a Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Wed, 2 Oct 2024 12:42:03 -0300 Subject: [PATCH 03/11] feat: use create body method from trait on response --- src/Utils/Curl/Response.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Utils/Curl/Response.php b/src/Utils/Curl/Response.php index 3148e78d..694ca969 100644 --- a/src/Utils/Curl/Response.php +++ b/src/Utils/Curl/Response.php @@ -60,14 +60,4 @@ public function withAddedHeader($name, $value): ResponseInterface $new->headers[$name][] = $value; return $new; } - - private function createBody($body = ''): StreamInterface - { - $resource = fopen('php://temp', 'rw+'); - if (!empty($body)) { - fwrite($resource, $body); - } - - return new Stream($resource); - } } From 20ce76cbecb7114d006d9dfd7c91cc5cc03aab14 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Wed, 2 Oct 2024 12:43:14 -0300 Subject: [PATCH 04/11] feat: use create body method from trait on request --- src/Utils/Curl/Request.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Utils/Curl/Request.php b/src/Utils/Curl/Request.php index 4e86e25b..4be1c1c0 100644 --- a/src/Utils/Curl/Request.php +++ b/src/Utils/Curl/Request.php @@ -79,14 +79,4 @@ public function withAddedHeader($name, $value): RequestInterface { return clone $this; } - - private function createBody($body = ''): StreamInterface - { - $resource = fopen('php://temp', 'rw+'); - if (!empty($body)) { - fwrite($resource, $body); - } - - return new Stream($resource); - } } From b091de11380f8f06d2641a96649d961d4559e697 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 09:55:08 -0300 Subject: [PATCH 05/11] test: avoid fopen use on stream test --- tests/Utils/Curl/StreamTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Utils/Curl/StreamTest.php b/tests/Utils/Curl/StreamTest.php index 16b1c756..1b42274e 100644 --- a/tests/Utils/Curl/StreamTest.php +++ b/tests/Utils/Curl/StreamTest.php @@ -2,6 +2,7 @@ use PHPUnit\Framework\TestCase; use Transbank\Utils\Curl\Stream; +use Transbank\Utils\Curl\Response; use Transbank\Utils\Curl\Exceptions\StreamException; class StreamTest extends TestCase @@ -10,9 +11,9 @@ class StreamTest extends TestCase public function setUp(): void { - $resource = fopen('php://temp', 'rw+'); - fwrite($resource, 'this is a test data for stream'); - $this->stream = new Stream($resource); + $response = new Response(200, [], 'this is a test data for stream'); + $stream = $response->getBody(); + $this->stream = $stream; } /** @test */ @@ -26,7 +27,7 @@ public function it_throws_exception_on_constructor_failure() public function it_gets_empty_string_on_failure() { $mockStream = $this->getMockBuilder(Stream::class) - ->setConstructorArgs([fopen('php://temp', 'r')]) + ->disableOriginalConstructor() ->onlyMethods(['isSeekable']) ->getMock(); $mockStream->method('isSeekable')->willThrowException(new Exception('test Exception')); From 97d46b89082e0240b355e826c4074a3cb8c7bc0d Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:02:20 -0300 Subject: [PATCH 06/11] feat: add header methods on message trait --- src/Utils/Curl/MessageTrait.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Utils/Curl/MessageTrait.php b/src/Utils/Curl/MessageTrait.php index 63b5a6ba..9a77ffaa 100644 --- a/src/Utils/Curl/MessageTrait.php +++ b/src/Utils/Curl/MessageTrait.php @@ -62,6 +62,20 @@ public function withBody(StreamInterface $body): static return $new; } + public function withHeader($name, $value): static + { + $new = clone $this; + $new->headers[$name] = (array) $value; + return $new; + } + + public function withAddedHeader($name, $value): static + { + $new = clone $this; + $new->headers[$name][] = $value; + return $new; + } + private function createBody($body = ''): StreamInterface { $resource = fopen('php://temp', 'rw+'); From 672f77739cbdbf0f8b3c73fec16d75e34fb13d4a Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:02:45 -0300 Subject: [PATCH 07/11] feat: use header methods from trait on request class --- src/Utils/Curl/Request.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Utils/Curl/Request.php b/src/Utils/Curl/Request.php index 4be1c1c0..9f470e3a 100644 --- a/src/Utils/Curl/Request.php +++ b/src/Utils/Curl/Request.php @@ -69,14 +69,4 @@ public function withUri(UriInterface $uri, $preserveHost = false): RequestInterf return $new; } - - public function withHeader($name, $value): RequestInterface - { - return clone $this; - } - - public function withAddedHeader($name, $value): RequestInterface - { - return clone $this; - } } From b8c759b1ffd784d2fa715971e53c2dcdc75b8da0 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:03:03 -0300 Subject: [PATCH 08/11] feat: use header methods from trait on response class --- src/Utils/Curl/Response.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Utils/Curl/Response.php b/src/Utils/Curl/Response.php index 694ca969..3fe21ec6 100644 --- a/src/Utils/Curl/Response.php +++ b/src/Utils/Curl/Response.php @@ -46,18 +46,4 @@ public function getReasonPhrase(): string { return $this->reasonPhrase; } - - public function withHeader($name, $value): ResponseInterface - { - $new = clone $this; - $new->headers[$name] = (array) $value; - return $new; - } - - public function withAddedHeader($name, $value): ResponseInterface - { - $new = clone $this; - $new->headers[$name][] = $value; - return $new; - } } From 8e356cba98eb607b8a81dda11c6e4b4cc934d987 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:03:27 -0300 Subject: [PATCH 09/11] test: avoid fopen use on request tests --- tests/Utils/Curl/RequestTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Utils/Curl/RequestTest.php b/tests/Utils/Curl/RequestTest.php index aefc5bfe..d6ac5805 100644 --- a/tests/Utils/Curl/RequestTest.php +++ b/tests/Utils/Curl/RequestTest.php @@ -60,10 +60,12 @@ public function it_can_set_class_properties(): void $this->assertEquals([], $newRequest->getHeader('Accept')); $this->assertNotSame($newRequest, $this->request); - - $resource = fopen('php://temp', 'rw+'); - fwrite($resource, 'testData'); - $newRequest = $this->request->withBody(new Stream($resource)); + $secondRequest = + new Request('GET', 'https://www.transbank.cl:443/webpay/1.2/transactions/token?param1=123¶m2=222', [ + 'Accept' => 'text/plain', + 'api_key' => 'fakeApiKey' + ], 'this is a new body', '1.2'); + $newRequest = $this->request->withBody($secondRequest->getBody()); $this->assertFalse($newRequest->getBody() == $this->request->getBody()); $this->assertNotSame($newRequest, $this->request); } From 4b7bd048915808e370596f9aa160150de094505a Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:04:03 -0300 Subject: [PATCH 10/11] test: avoid fopen use on response test --- tests/Utils/Curl/ResponseTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Utils/Curl/ResponseTest.php b/tests/Utils/Curl/ResponseTest.php index b5cbbc30..fa2bf164 100644 --- a/tests/Utils/Curl/ResponseTest.php +++ b/tests/Utils/Curl/ResponseTest.php @@ -52,10 +52,11 @@ public function it_can_set_class_properties(): void $this->assertEquals([], $newResponse->getHeader('Accept')); $this->assertNotSame($newResponse, $this->response); - - $resource = fopen('php://temp', 'rw+'); - fwrite($resource, 'testData'); - $newResponse = $this->response->withBody(new Stream($resource)); + $secondResponse = new Response(200, [ + 'Accept' => 'text/plain', + 'api_key' => 'fakeApiKey' + ], 'a text for body'); + $newResponse = $this->response->withBody($secondResponse->getBody()); $this->assertFalse($newResponse->getBody() == $this->response->getBody()); $this->assertNotSame($newResponse, $this->response); } From 4483b1dc5c53e8c7bd831580275d34d479a452ac Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 3 Oct 2024 12:40:59 -0300 Subject: [PATCH 11/11] refactor: remove unused imports --- tests/Utils/Curl/RequestTest.php | 1 - tests/Utils/Curl/ResponseTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/Utils/Curl/RequestTest.php b/tests/Utils/Curl/RequestTest.php index d6ac5805..88eabfea 100644 --- a/tests/Utils/Curl/RequestTest.php +++ b/tests/Utils/Curl/RequestTest.php @@ -3,7 +3,6 @@ use PHPUnit\Framework\TestCase; use Transbank\Utils\Curl\Request; use Transbank\Utils\Curl\Uri; -use Transbank\Utils\Curl\Stream; class RequestTest extends TestCase diff --git a/tests/Utils/Curl/ResponseTest.php b/tests/Utils/Curl/ResponseTest.php index fa2bf164..2a0643ac 100644 --- a/tests/Utils/Curl/ResponseTest.php +++ b/tests/Utils/Curl/ResponseTest.php @@ -2,7 +2,6 @@ use PHPUnit\Framework\TestCase; use Transbank\Utils\Curl\Response; -use Transbank\Utils\Curl\Stream; class ResponseTest extends TestCase