diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index 4cb739c5..ee5b11ed 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -20,9 +20,9 @@ class GetAllMethodsRequest extends ResourceHydratableRequest private GetAllMethodsQuery $query; - public function __construct(GetAllMethodsQuery $query) + public function __construct(?GetAllMethodsQuery $query = null) { - $this->query = $query; + $this->query = $query ?: new GetAllMethodsQuery(); } protected function defaultQuery(): array diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 2073dda9..5644822f 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -20,9 +20,9 @@ class GetClientRequest extends ResourceHydratableRequest private string $id; - private GetClientQuery $query; + private ?GetClientQuery $query; - public function __construct(string $id, GetClientQuery $query) + public function __construct(string $id, ?GetClientQuery $query = null) { $this->id = $id; $this->query = $query; @@ -30,7 +30,7 @@ public function __construct(string $id, GetClientQuery $query) protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php index 8888b4d5..c628a16c 100644 --- a/src/Http/Requests/GetEnabledMethodsRequest.php +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -13,16 +13,16 @@ class GetEnabledMethodsRequest extends ResourceHydratableRequest implements Supp public static string $targetResourceClass = MethodCollection::class; - private GetEnabledPaymentMethodsQuery $query; + private ?GetEnabledPaymentMethodsQuery $query = null; - public function __construct(GetEnabledPaymentMethodsQuery $query) + public function __construct(?GetEnabledPaymentMethodsQuery $query = null) { $this->query = $query; } protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php index 4b85f334..44cd639e 100644 --- a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -20,7 +20,7 @@ class GetPaginatedBalanceTransactionRequest extends PaginatedRequest implements public function __construct( string $balanceId, - PaginatedQuery $query + ?PaginatedQuery $query = null ) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php index 52c1e403..26de07c6 100644 --- a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php @@ -21,7 +21,7 @@ class GetPaginatedCustomerPaymentsRequest extends PaginatedRequest implements Is public function __construct( string $customerId, - GetPaginatedCustomerPaymentsQuery $query + ?GetPaginatedCustomerPaymentsQuery $query = null ) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedMandateRequest.php b/src/Http/Requests/GetPaginatedMandateRequest.php index 02622424..25a40772 100644 --- a/src/Http/Requests/GetPaginatedMandateRequest.php +++ b/src/Http/Requests/GetPaginatedMandateRequest.php @@ -19,7 +19,7 @@ class GetPaginatedMandateRequest extends PaginatedRequest implements IsIteratabl private string $customerId; - public function __construct(string $customerId, PaginatedQuery $query) + public function __construct(string $customerId, ?PaginatedQuery $query = null) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index e90b3e57..332e8fb1 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -21,7 +21,7 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement private string $subscriptionId; - public function __construct(string $customerId, string $subscriptionId, PaginatedQuery $query) + public function __construct(string $customerId, string $subscriptionId, ?PaginatedQuery $query = null) { $this->customerId = $customerId; $this->subscriptionId = $subscriptionId; diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index 62f027d3..2e6eb379 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -19,7 +19,7 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte private string $customerId; - public function __construct(string $customerId, PaginatedQuery $query) + public function __construct(string $customerId, ?PaginatedQuery $query = null) { $this->customerId = $customerId; diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php index 968f0e66..37686734 100644 --- a/src/Http/Requests/GetPaymentMethodRequest.php +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -13,11 +13,11 @@ class GetPaymentMethodRequest extends ResourceHydratableRequest implements Suppo public static string $targetResourceClass = Method::class; - private GetPaymentMethodQuery $query; + private ?GetPaymentMethodQuery $query = null; private string $methodId; - public function __construct(string $methodId, GetPaymentMethodQuery $query) + public function __construct(string $methodId, ?GetPaymentMethodQuery $query = null) { $this->methodId = $methodId; $this->query = $query; @@ -25,7 +25,7 @@ public function __construct(string $methodId, GetPaymentMethodQuery $query) protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index 51b6e2a9..e0917158 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -23,9 +23,9 @@ class GetPaymentRefundRequest extends ResourceHydratableRequest implements Suppo private string $refundId; - private GetPaymentRefundQuery $query; + private ?GetPaymentRefundQuery $query = null; - public function __construct(string $paymentId, string $refundId, GetPaymentRefundQuery $query) + public function __construct(string $paymentId, string $refundId, ?GetPaymentRefundQuery $query = null) { $this->paymentId = $paymentId; $this->refundId = $refundId; @@ -34,7 +34,7 @@ public function __construct(string $paymentId, string $refundId, GetPaymentRefun protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } /** diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 4e723d00..d2031411 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -21,11 +21,11 @@ class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTes private string $id; - private GetPaymentQuery $query; + private ?GetPaymentQuery $query = null; public function __construct( string $id, - GetPaymentQuery $query + ?GetPaymentQuery $query = null ) { $this->id = $id; $this->query = $query; @@ -33,7 +33,7 @@ public function __construct( protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } /** diff --git a/src/Http/Response.php b/src/Http/Response.php index 32be2f4e..276da835 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -5,6 +5,9 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Requests\ResourceHydratableRequest; +use Mollie\Api\Resources\BaseResource; +use Mollie\Api\Resources\ResourceCollection; +use Mollie\Api\Traits\DelegatesToResource; use Mollie\Api\Traits\HandlesResourceHydration; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -14,6 +17,7 @@ class Response { + use DelegatesToResource; use HandlesResourceHydration; protected ResponseInterface $psrResponse; @@ -24,6 +28,11 @@ class Response protected ?Throwable $senderException = null; + /** + * @var null|BaseResource|ResourceCollection + */ + protected $resource = null; + /** * The decoded JSON response. */ @@ -42,7 +51,7 @@ public function __construct( } /** - * @return mixed + * @return self|BaseResource|ResourceCollection|null */ public function toResource() { @@ -50,7 +59,7 @@ public function toResource() return $this; } - return $this->hydrate($this->getRequest(), $this); + return $this->resource ?: $this->resource = $this->hydrate($this->getRequest(), $this); } /** diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 078a478e..6959751d 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -4,43 +4,17 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\ResourceHydratableRequest; +use Mollie\Api\Http\Response; abstract class CursorCollection extends ResourceCollection { - private bool $autoHydrate = false; - - public function setAutoHydrate(bool $shouldAutoHydrate = true): void - { - $this->autoHydrate = $shouldAutoHydrate; - } - - public function shouldAutoHydrate(): bool - { - if ($this->response === null) { - return $this->autoHydrate; - } - - $request = $this->response->getRequest(); - - /** - * Don't try to hydrate when the request - * already has auto-hydration enabled. The - * Hydrate Middleware will take care of that. - */ - if ($request instanceof ResourceHydratableRequest && $request->shouldAutoHydrate()) { - return false; - } - - return $this->autoHydrate; - } - /** * Return the next set of resources when available * + * @return null|CursorCollection|Response * @throws \Mollie\Api\Exceptions\ApiException */ - public function next(): ?CursorCollection + public function next() { if (! $this->hasNext()) { return null; @@ -52,9 +26,10 @@ public function next(): ?CursorCollection /** * Return the previous set of resources when available * + * @return null|CursorCollection|Response * @throws \Mollie\Api\Exceptions\ApiException */ - public function previous(): ?CursorCollection + public function previous() { if (! $this->hasPrevious()) { return null; @@ -63,15 +38,14 @@ public function previous(): ?CursorCollection return $this->fetchCollection($this->_links->previous->href); } - private function fetchCollection(string $url): CursorCollection + /** + * @return CursorCollection|Response + */ + private function fetchCollection(string $url) { - $response = $this + return $this ->connector ->send(new DynamicGetRequest($url, static::class)); - - return $this->shouldAutoHydrate() - ? $response->toResource() - : $response; } /** @@ -99,8 +73,6 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection return new LazyCollection(function () use ($page, $iterateBackwards): Generator { while (true) { - $page->setAutoHydrate(); - foreach ($page as $item) { yield $item; } @@ -109,9 +81,13 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection break; } - $page = $iterateBackwards + $response = $iterateBackwards ? $page->previous() : $page->next(); + + $page = $response instanceof Response + ? $response->toResource() + : $response; } }); } diff --git a/src/Traits/DelegatesToResource.php b/src/Traits/DelegatesToResource.php new file mode 100644 index 00000000..3d3824a7 --- /dev/null +++ b/src/Traits/DelegatesToResource.php @@ -0,0 +1,90 @@ +ensureResourceIsLoaded(); + + return isset($this->resource->{$key}); + } + + /** + * Unset an attribute on the resource. + * + * @param string $key + * @return void + */ + public function __unset($key) + { + $this->ensureResourceIsLoaded(); + + unset($this->resource->{$key}); + } + + /** + * Dynamically get properties from the underlying resource. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + $this->ensureResourceIsLoaded(); + + if (!property_exists($this->resource, $key)) { + throw new \InvalidArgumentException("Property {$key} does not exist on resource."); + } + + $reflectionProperty = new ReflectionProperty($this->resource, $key); + + return $reflectionProperty->getValue($this->resource); + } + + /** + * Dynamically pass method calls to the underlying resource. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + $this->ensureResourceIsLoaded(); + + if (method_exists($this->resource, $method)) { + return call_user_func_array([$this->resource, $method], $parameters); + } + + throw new \BadMethodCallException("Method {$method} does not exist on resource."); + } + + /** + * Ensure the resource is loaded. + */ + private function ensureResourceIsLoaded(): void + { + if ($this->resource) { + return; + } + + $this->toResource(); + } +} diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index 237eb8c7..000cc813 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -34,6 +35,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); foreach ($client->chargebacks->iterator() as $chargeback) { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index 09861ed4..b4a28673 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; @@ -49,6 +50,7 @@ public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); foreach ($client->paymentChargebacks->iteratorForId('tr_7UhSN1zuXS') as $chargeback) { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 78f99be1..6b6ac696 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -38,6 +39,7 @@ public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); $settlement = new Settlement($client); diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index 337af014..a3dcf54c 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -50,6 +50,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'terminals'), ]); foreach ($client->terminals->iterator() as $terminal) { diff --git a/tests/Fixtures/MockClient.php b/tests/Fixtures/MockClient.php index 79983cb0..c5ce8e5b 100644 --- a/tests/Fixtures/MockClient.php +++ b/tests/Fixtures/MockClient.php @@ -5,6 +5,9 @@ use Mollie\Api\MollieApiClient; use Tests\Http\Adapter\MockMollieHttpAdapter; +/** + * @property MockMollieHttpAdapter $httpClient + */ class MockClient extends MollieApiClient { public function __construct(array $expectedResponses = []) @@ -15,4 +18,17 @@ public function __construct(array $expectedResponses = []) $this->setAccessToken('access_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); } + + /** + * @param string|callable $callback + */ + public function assertSent($callback): void + { + $this->httpClient->assertSent($callback); + } + + public function assertSentCount(int $count): void + { + $this->httpClient->assertSentCount($count); + } } diff --git a/tests/Fixtures/Responses/chargeback-list.json b/tests/Fixtures/Responses/chargeback-list.json index 440c06ea..91e36fd1 100644 --- a/tests/Fixtures/Responses/chargeback-list.json +++ b/tests/Fixtures/Responses/chargeback-list.json @@ -202,6 +202,9 @@ "type": "application/hal+json" }, "previous": null, - "next": null + "next": { + "href": "...", + "type": "application/hal+json" + } } } diff --git a/tests/Fixtures/Responses/terminal-list.json b/tests/Fixtures/Responses/terminal-list.json index 2a4f4810..bf081f8f 100644 --- a/tests/Fixtures/Responses/terminal-list.json +++ b/tests/Fixtures/Responses/terminal-list.json @@ -29,7 +29,10 @@ "type": "application/hal+json" }, "previous": null, - "next": null, + "next": { + "href": "...", + "type": "application/hal+json" + }, "documentation": { "href": "...", "type": "text/html" diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 54b405ba..6f155f37 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -9,6 +9,7 @@ use Mollie\Api\Traits\HasDefaultFactories; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; +use PHPUnit\Framework\Assert as PHPUnit; class MockMollieHttpAdapter implements HttpAdapterContract { @@ -17,11 +18,13 @@ class MockMollieHttpAdapter implements HttpAdapterContract /** * @var array */ - private array $expectedResponses; + private array $expected; + + private array $recorded = []; public function __construct(array $expectedResponses = []) { - $this->expectedResponses = $expectedResponses; + $this->expected = $expectedResponses; } /** @@ -29,19 +32,28 @@ public function __construct(array $expectedResponses = []) */ public function sendRequest(PendingRequest $pendingRequest): Response { - $requestClass = get_class($pendingRequest->getRequest()); + $requestClass = get_class($request = $pendingRequest->getRequest()); - if (! Arr::has($this->expectedResponses, $requestClass)) { - throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); - } + $this->guardAgainstStrayRequests($requestClass); $mockedResponse = $this->getResponse($requestClass); - return new Response( + $response = new Response( $mockedResponse->createPsrResponse(), $pendingRequest->createPsrRequest(), $pendingRequest, ); + + $this->recorded[] = [$request, $response]; + + return $response; + } + + private function guardAgainstStrayRequests(string $requestClass): void + { + if (! Arr::has($this->expected, $requestClass)) { + throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); + } } /** @@ -49,10 +61,10 @@ public function sendRequest(PendingRequest $pendingRequest): Response */ private function getResponse(string $requestClass): MockResponse { - $mockedResponse = Arr::get($this->expectedResponses, $requestClass); + $mockedResponse = Arr::get($this->expected, $requestClass); if (! ($mockedResponse instanceof SequenceMockResponse)) { - Arr::forget($this->expectedResponses, $requestClass); + Arr::forget($this->expected, $requestClass); return $mockedResponse; } @@ -60,12 +72,45 @@ private function getResponse(string $requestClass): MockResponse $response = $mockedResponse->pop(); if ($mockedResponse->isEmpty()) { - Arr::forget($this->expectedResponses, $requestClass); + Arr::forget($this->expected, $requestClass); } return $response; } + public function recorded(callable $callback = null): array + { + if ($callback === null) { + return $this->recorded; + } + + return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); + } + + /** + * @param string|callable $callback + */ + public function assertSent($callback): void + { + if (is_string($callback)) { + $callback = fn ($request) => get_class($request) === $callback; + } + + PHPUnit::assertTrue( + count($this->recorded($callback)) > 0, + 'No requests were sent.' + ); + } + + public function assertSentCount(int $count): void + { + PHPUnit::assertEquals( + $count, + count($this->recorded), + 'The expected number of requests was not sent.' + ); + } + /** * {@inheritDoc} */ diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php new file mode 100644 index 00000000..6c489880 --- /dev/null +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -0,0 +1,53 @@ + new MockResponse(200, 'apple-pay-session'), + ]); + + $payload = new RequestApplePayPaymentSessionPayload( + 'https://example.com', + 'Example Domain', + 'EUR' + ); + + $request = new ApplePayPaymentSessionRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(AnyResource::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $payload = new RequestApplePayPaymentSessionPayload( + 'https://example.com', + 'Example Domain', + 'EUR' + ); + + $request = new ApplePayPaymentSessionRequest($payload); + + $this->assertEquals( + 'wallets/applepay/sessions', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelPaymentRefundRequestTest.php b/tests/Http/Requests/CancelPaymentRefundRequestTest.php new file mode 100644 index 00000000..bf1d15d8 --- /dev/null +++ b/tests/Http/Requests/CancelPaymentRefundRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $paymentId = 'tr_7UhSN1zuXS'; + $refundId = 're_4qqhO89gsT'; + + $request = new CancelPaymentRefundRequest($paymentId, $refundId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_7UhSN1zuXS'; + $refundId = 're_4qqhO89gsT'; + + $request = new CancelPaymentRefundRequest($paymentId, $refundId); + + $this->assertEquals( + "payments/{$paymentId}/refunds/{$refundId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelPaymentRequestTest.php b/tests/Http/Requests/CancelPaymentRequestTest.php new file mode 100644 index 00000000..e1fb1e95 --- /dev/null +++ b/tests/Http/Requests/CancelPaymentRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'payment'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $request = new CancelPaymentRequest($paymentId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new CancelPaymentRequest($paymentId); + + $this->assertEquals( + "payments/{$paymentId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelSessionRequestTest.php b/tests/Http/Requests/CancelSessionRequestTest.php new file mode 100644 index 00000000..1eb90c80 --- /dev/null +++ b/tests/Http/Requests/CancelSessionRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'session'), + ]); + + $sessionId = 'sess_pNxqdWEFws'; + $request = new CancelSessionRequest($sessionId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Session::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $sessionId = 'sess_pNxqdWEFws'; + $request = new CancelSessionRequest($sessionId); + + $this->assertEquals( + "sessions/{$sessionId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelSubscriptionRequestTest.php b/tests/Http/Requests/CancelSubscriptionRequestTest.php new file mode 100644 index 00000000..b468e2f5 --- /dev/null +++ b/tests/Http/Requests/CancelSubscriptionRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'subscription'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new CancelSubscriptionRequest($customerId, $subscriptionId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new CancelSubscriptionRequest($customerId, $subscriptionId); + + $this->assertEquals( + "customers/{$customerId}/subscriptions/{$subscriptionId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php new file mode 100644 index 00000000..45aece5d --- /dev/null +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(201, 'client-link'), + ]); + + $payload = new CreateClientLinkPayload( + new Owner('test@example.org', 'John', 'Doe'), + 'Test', + new OwnerAddress('NL') + ); + + $request = new CreateClientLinkRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ClientLink::class, $response->toResource()); + } +} diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php new file mode 100644 index 00000000..a6f58749 --- /dev/null +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -0,0 +1,55 @@ + new MockResponse(201, 'payment'), + ]); + + $payload = new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect' + ); + + $request = new CreateCustomerPaymentRequest( + 'cst_123', + $payload, + new CreatePaymentQuery(true) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_123'; + $request = new CreateCustomerPaymentRequest($customerId, new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect' + )); + + $this->assertEquals("customers/{$customerId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php new file mode 100644 index 00000000..890bfcad --- /dev/null +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -0,0 +1,46 @@ + new MockResponse(201, 'customer'), + ]); + + $payload = new CreateCustomerPayload( + 'John Doe', + 'john@example.org' + ); + + $request = new CreateCustomerRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Customer::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateCustomerRequest(new CreateCustomerPayload( + 'John Doe', + 'john@example.org' + )); + + $this->assertEquals('customers', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php new file mode 100644 index 00000000..e91618f9 --- /dev/null +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -0,0 +1,55 @@ + new MockResponse(201, 'mandate'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $payload = new CreateMandatePayload( + 'directdebit', + 'John Doe', + 'NL55INGB0000000000' + ); + + $request = new CreateMandateRequest($customerId, $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Mandate::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $payload = new CreateMandatePayload( + 'directdebit', + 'John Doe', + 'NL55INGB0000000000' + ); + + $request = new CreateMandateRequest($customerId, $payload); + + $this->assertEquals( + "customers/{$customerId}/mandates", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php new file mode 100644 index 00000000..ce9908b7 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'capture'), + ]); + + $payload = new CreatePaymentCapturePayload( + 'Test capture', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentCaptureRequest('tr_123', $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Capture::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentCaptureRequest('tr_123', new CreatePaymentCapturePayload( + 'Test capture', + new Money('EUR', '10.00') + )); + + $this->assertEquals('payments/tr_123/captures', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php new file mode 100644 index 00000000..ba854938 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'payment-link'), + ]); + + $payload = new CreatePaymentLinkPayload( + 'Test payment link', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentLinkRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(PaymentLink::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentLinkRequest(new CreatePaymentLinkPayload( + 'Test payment link', + new Money('EUR', '10.00') + )); + + $this->assertEquals('payment-links', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php new file mode 100644 index 00000000..fda09f84 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -0,0 +1,54 @@ + new MockResponse(201, 'refund'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $payload = new CreateRefundPaymentPayload( + 'Order cancellation', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentRefundRequest($paymentId, $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Refund::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $payload = new CreateRefundPaymentPayload( + 'Order cancellation', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentRefundRequest($paymentId, $payload); + + $this->assertEquals( + "payments/{$paymentId}/refunds", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index 4758be8a..b7c01a7d 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -35,4 +35,17 @@ public function it_can_create_payment() $this->assertTrue($response->successful()); $this->assertInstanceOf(Payment::class, $response->toResource()); } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentRequest(new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + )); + + $this->assertEquals('payments', $request->resolveResourcePath()); + } } diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php new file mode 100644 index 00000000..f1a5e305 --- /dev/null +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -0,0 +1,52 @@ + new MockResponse(201, 'profile'), + ]); + + $payload = new CreateProfilePayload( + 'Test profile', + 'https://example.org', + 'test@example.org', + 'en_US', + '+31612345678' + ); + + $request = new CreateProfileRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Profile::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateProfileRequest(new CreateProfilePayload( + 'Test profile', + 'https://example.org', + 'test@example.org', + 'en_US', + '+31612345678' + )); + + $this->assertEquals('profiles', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php new file mode 100644 index 00000000..2c47d5c7 --- /dev/null +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(201, 'session'), + ]); + + $request = new CreateSessionRequest( + new AnyPayload(['foo' => 'bar']), + new AnyQuery(['baz' => 'qux']) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Session::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateSessionRequest(new AnyPayload(['foo' => 'bar']), new AnyQuery(['baz' => 'qux'])); + + $this->assertEquals('sessions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php new file mode 100644 index 00000000..e08a183c --- /dev/null +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'subscription'), + ]); + + $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( + new Money('EUR', '10.00'), + '1 month', + 'Test subscription' + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( + new Money('EUR', '10.00'), + '1 month', + 'Test subscription' + )); + + $this->assertEquals('customers/cst_123/subscriptions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeleteCustomerRequestTest.php b/tests/Http/Requests/DeleteCustomerRequestTest.php new file mode 100644 index 00000000..3fe352d8 --- /dev/null +++ b/tests/Http/Requests/DeleteCustomerRequestTest.php @@ -0,0 +1,36 @@ + new MockResponse(204), + ]); + + $request = new DeleteCustomerRequest('cst_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new DeleteCustomerRequest('cst_123'); + + $this->assertEquals('customers/cst_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeletePaymentLinkRequestTest.php b/tests/Http/Requests/DeletePaymentLinkRequestTest.php new file mode 100644 index 00000000..0a112a24 --- /dev/null +++ b/tests/Http/Requests/DeletePaymentLinkRequestTest.php @@ -0,0 +1,36 @@ + new MockResponse(204), + ]); + + $request = new DeletePaymentLinkRequest('pl_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new DeletePaymentLinkRequest('pl_123'); + + $this->assertEquals('payment-links/pl_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeleteProfileRequestTest.php b/tests/Http/Requests/DeleteProfileRequestTest.php new file mode 100644 index 00000000..339fc268 --- /dev/null +++ b/tests/Http/Requests/DeleteProfileRequestTest.php @@ -0,0 +1,41 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $request = new DeleteProfileRequest($profileId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $request = new DeleteProfileRequest($profileId); + + $this->assertEquals( + "profiles/{$profileId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DisableMethodIssuerRequestTest.php b/tests/Http/Requests/DisableMethodIssuerRequestTest.php new file mode 100644 index 00000000..60741dbb --- /dev/null +++ b/tests/Http/Requests/DisableMethodIssuerRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new DisableMethodIssuerRequest($profileId, $methodId, $issuerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new DisableMethodIssuerRequest($profileId, $methodId, $issuerId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}/issuers/{$issuerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DisableProfileMethodRequestTest.php b/tests/Http/Requests/DisableProfileMethodRequestTest.php new file mode 100644 index 00000000..fbb39aea --- /dev/null +++ b/tests/Http/Requests/DisableProfileMethodRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new DisableProfileMethodRequest($profileId, $methodId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new DisableProfileMethodRequest($profileId, $methodId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DynamicGetRequestTest.php b/tests/Http/Requests/DynamicGetRequestTest.php new file mode 100644 index 00000000..7db9ee1a --- /dev/null +++ b/tests/Http/Requests/DynamicGetRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'payment'), + ]); + + $request = new DynamicGetRequest( + 'payments/tr_WDqYK6vllg', + Payment::class, + ['testmode' => 'true'] + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $path = 'payments/tr_WDqYK6vllg'; + $request = new DynamicGetRequest($path, Payment::class); + + $this->assertEquals($path, $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php new file mode 100644 index 00000000..700924ed --- /dev/null +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -0,0 +1,45 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("The resource class 'NonExistentClass' does not exist."); + + /** @phpstan-ignore-next-line */ + new class('some-url', 'NonExistentClass') extends DynamicRequest { + protected static string $method = Method::GET; + }; + } + + /** @test */ + public function it_accepts_valid_resource_class() + { + $request = new class('some-url', Payment::class) extends DynamicRequest { + protected static string $method = Method::GET; + }; + + $this->assertEquals(Payment::class, $request->getTargetResourceClass()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $url = 'https://example.org'; + $request = new class($url, Payment::class) extends DynamicRequest { + protected static string $method = Method::GET; + }; + + $this->assertEquals($url, $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/EnableMethodIssuerRequestTest.php b/tests/Http/Requests/EnableMethodIssuerRequestTest.php new file mode 100644 index 00000000..a0a1939d --- /dev/null +++ b/tests/Http/Requests/EnableMethodIssuerRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new EnableMethodIssuerRequest($profileId, $methodId, $issuerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new EnableMethodIssuerRequest($profileId, $methodId, $issuerId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}/issuers/{$issuerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/EnableProfileMethodRequestTest.php b/tests/Http/Requests/EnableProfileMethodRequestTest.php new file mode 100644 index 00000000..95ab9c58 --- /dev/null +++ b/tests/Http/Requests/EnableProfileMethodRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new EnableProfileMethodRequest($profileId, $methodId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new EnableProfileMethodRequest($profileId, $methodId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php new file mode 100644 index 00000000..be2aeeb7 --- /dev/null +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'method-list'), + ]); + + $request = new GetAllMethodsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetAllMethodsRequest(); + + $this->assertEquals('methods/all', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php new file mode 100644 index 00000000..94cfa4f3 --- /dev/null +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'subscription-list'), + ]); + + $request = new GetAllPaginatedSubscriptionsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(SubscriptionCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetAllPaginatedSubscriptionsRequest(); + + $this->assertEquals('subscriptions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php new file mode 100644 index 00000000..cae89d72 --- /dev/null +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'balance-report'), + ]); + + $request = new GetBalanceReportRequest( + 'bal_12345', + new GetBalanceReportQuery( + new DateTime('2024-01-01'), + new DateTime('2024-01-31'), + ) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceReport::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetBalanceReportRequest('bal_12345', new GetBalanceReportQuery( + new DateTime('2024-01-01'), + new DateTime('2024-01-31'), + )); + + $this->assertEquals('balances/bal_12345/report', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetBalanceRequestTest.php b/tests/Http/Requests/GetBalanceRequestTest.php new file mode 100644 index 00000000..60230163 --- /dev/null +++ b/tests/Http/Requests/GetBalanceRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'balance'), + ]); + + $balanceId = 'bal_12345678'; + $request = new GetBalanceRequest($balanceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Balance::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $balanceId = 'bal_12345678'; + $request = new GetBalanceRequest($balanceId); + + $this->assertEquals( + "balances/{$balanceId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php new file mode 100644 index 00000000..bff99d57 --- /dev/null +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -0,0 +1,39 @@ + new MockResponse(200, 'client'), + ]); + + $request = new GetClientRequest('client_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Client::class, $response->toResource()); + $this->assertEquals('client', $response->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetClientRequest('client_123'); + + $this->assertEquals('clients/client_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetCustomerRequestTest.php b/tests/Http/Requests/GetCustomerRequestTest.php new file mode 100644 index 00000000..4626f72c --- /dev/null +++ b/tests/Http/Requests/GetCustomerRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'customer'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $request = new GetCustomerRequest($customerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Customer::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetCustomerRequest($customerId); + + $this->assertEquals( + "customers/{$customerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php new file mode 100644 index 00000000..34c77ac6 --- /dev/null +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'method-list'), + ]); + + $request = new GetEnabledMethodsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetEnabledMethodsRequest(); + + $this->assertEquals('methods', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetInvoiceRequestTest.php b/tests/Http/Requests/GetInvoiceRequestTest.php new file mode 100644 index 00000000..4dda901b --- /dev/null +++ b/tests/Http/Requests/GetInvoiceRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'invoice'), + ]); + + $invoiceId = 'inv_xBEbP9rvAq'; + $request = new GetInvoiceRequest($invoiceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Invoice::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetInvoiceRequest('inv_xBEbP9rvAq'); + + $this->assertEquals('invoices/inv_xBEbP9rvAq', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetMandateRequestTest.php b/tests/Http/Requests/GetMandateRequestTest.php new file mode 100644 index 00000000..2178d288 --- /dev/null +++ b/tests/Http/Requests/GetMandateRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'mandate'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new GetMandateRequest($customerId, $mandateId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Mandate::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new GetMandateRequest($customerId, $mandateId); + + $this->assertEquals( + "customers/{$customerId}/mandates/{$mandateId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetOnboardingRequestTest.php b/tests/Http/Requests/GetOnboardingRequestTest.php new file mode 100644 index 00000000..aa03c01f --- /dev/null +++ b/tests/Http/Requests/GetOnboardingRequestTest.php @@ -0,0 +1,37 @@ + new MockResponse(200, 'onboarding'), + ]); + + $request = new GetOnboardingRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Onboarding::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetOnboardingRequest(); + + $this->assertEquals('onboarding/me', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php new file mode 100644 index 00000000..fb4ad513 --- /dev/null +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'partner-status'), + ]); + + $request = new GetOrganizationPartnerStatusRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Partner::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetOrganizationPartnerStatusRequest(); + + $this->assertEquals('organizations/me/partner', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetOrganizationRequestTest.php b/tests/Http/Requests/GetOrganizationRequestTest.php new file mode 100644 index 00000000..97fb103e --- /dev/null +++ b/tests/Http/Requests/GetOrganizationRequestTest.php @@ -0,0 +1,39 @@ + new MockResponse(200, 'organization'), + ]); + + $organizationId = 'org_1337'; + $request = new GetOrganizationRequest($organizationId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Organization::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $organizationId = 'org_1337'; + $request = new GetOrganizationRequest($organizationId); + + $this->assertEquals("organizations/{$organizationId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php new file mode 100644 index 00000000..a65e8915 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -0,0 +1,37 @@ + new MockResponse(200, 'balance-list'), + ]); + + $request = new GetPaginatedBalanceRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedBalanceRequest(); + + $this->assertEquals('balances', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php new file mode 100644 index 00000000..0b1aae7b --- /dev/null +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -0,0 +1,40 @@ + new MockResponse(200, 'balance-transactions'), + ]); + + $balanceId = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + $request = new GetPaginatedBalanceTransactionRequest($balanceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceTransactionCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $balanceId = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + $request = new GetPaginatedBalanceTransactionRequest($balanceId); + + $this->assertEquals("balances/{$balanceId}/transactions", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php new file mode 100644 index 00000000..001fab9c --- /dev/null +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedChargebacksRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ChargebackCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedChargebacksRequest(); + + $this->assertEquals('chargebacks', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php new file mode 100644 index 00000000..cce9a83b --- /dev/null +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'client-list'), + ]); + + $request = new GetPaginatedClientRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ClientCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedClientRequest(); + + $this->assertEquals('clients', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php new file mode 100644 index 00000000..facbbdd9 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -0,0 +1,40 @@ + new MockResponse(200, 'payment-list'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedCustomerPaymentsRequest($customerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(PaymentCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedCustomerPaymentsRequest($customerId); + + $this->assertEquals("customers/{$customerId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php new file mode 100644 index 00000000..654b58a2 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'customer-list'), + ]); + + $request = new GetPaginatedCustomerRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(CustomerCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedCustomerRequest(); + + $this->assertEquals('customers', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php new file mode 100644 index 00000000..3437ce5d --- /dev/null +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'invoice-list'), + ]); + + $request = new GetPaginatedInvoiceRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(InvoiceCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedInvoiceRequest(); + + $this->assertEquals('invoices', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedMandateRequestTest.php b/tests/Http/Requests/GetPaginatedMandateRequestTest.php new file mode 100644 index 00000000..33f8155c --- /dev/null +++ b/tests/Http/Requests/GetPaginatedMandateRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'mandate-list'), + ]); + + $request = new GetPaginatedMandateRequest('cst_kEn1PlbGa'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var MandateCollection */ + $mandates = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(MandateCollection::class, $mandates); + $this->assertGreaterThan(0, $mandates->count()); + + foreach ($mandates as $mandate) { + $this->assertInstanceOf(Mandate::class, $mandate); + $this->assertEquals('mandate', $mandate->resource); + } + } + + /** @test */ + public function it_can_iterate_over_mandates() + { + $client = new MockClient([ + GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'mandate-list'), + new MockResponse(200, 'empty-list', 'mandates'), + ), + ]); + + $request = (new GetPaginatedMandateRequest('cst_kEn1PlbGa'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $mandates = $response->toResource(); + + foreach ($mandates as $mandate) { + $this->assertInstanceOf(Mandate::class, $mandate); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedMandateRequest($customerId); + + $this->assertEquals("customers/{$customerId}/mandates", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php new file mode 100644 index 00000000..806af848 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'capture-list'), + ]); + + $request = new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var CaptureCollection */ + $captures = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertGreaterThan(0, $captures->count()); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + } + + /** @test */ + public function it_can_iterate_over_captures() + { + $client = new MockClient([ + GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'capture-list'), + new MockResponse(200, 'empty-list', 'captures'), + ), + ]); + + $request = (new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $captures = $response->toResource(); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentCapturesRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/captures", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php new file mode 100644 index 00000000..36b8cc13 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ChargebackCollection */ + $chargebacks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + } + + /** @test */ + public function it_can_iterate_over_chargebacks() + { + $client = new MockClient([ + GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'chargeback-list'), + new MockResponse(200, 'empty-list', 'chargebacks'), + ), + ]); + + $request = (new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $chargebacks = $response->toResource(); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentChargebacksRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/chargebacks", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php new file mode 100644 index 00000000..3514d3d4 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_payment_link_payments() + { + $client = new MockClient([ + GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentLinkId = 'pl_4Y0eZitmBnQ5jsBYZIBw'; + $request = new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId); + + $this->assertEquals("payment-links/{$paymentLinkId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php new file mode 100644 index 00000000..ad262369 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'payment-link-list'), + ]); + + $request = new GetPaginatedPaymentLinksRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLinkCollection */ + $paymentLinks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentLinkCollection::class, $paymentLinks); + $this->assertGreaterThan(0, $paymentLinks->count()); + + foreach ($paymentLinks as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + } + + /** @test */ + public function it_can_iterate_over_payment_links() + { + $client = new MockClient([ + GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-link-list'), + new MockResponse(200, 'empty-list', 'payment_links'), + ), + ]); + + $request = (new GetPaginatedPaymentLinksRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $paymentLinks = $response->toResource(); + + foreach ($paymentLinks as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedPaymentLinksRequest(); + + $this->assertEquals('payment-links', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php new file mode 100644 index 00000000..d5029305 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_refunds() + { + $client = new MockClient([ + GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentRefundsRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/refunds", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index b804844c..a3d8171c 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -10,6 +10,7 @@ use Mollie\Api\Resources\PaymentCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\Fixtures\SequenceMockResponse; use Tests\TestCase; class GetPaginatedPaymentsRequestTest extends TestCase @@ -45,8 +46,10 @@ public function it_can_iterate_over_payments() { $client = new MockClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), - DynamicGetRequest::class => new MockResponse(200, 'payment-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), ]); $request = (new GetPaginatedPaymentsRequest)->useIterator(); @@ -61,5 +64,15 @@ public function it_can_iterate_over_payments() foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedPaymentsRequest(); + + $this->assertEquals('payments', $request->resolveResourcePath()); } } diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php new file mode 100644 index 00000000..e1dd95db --- /dev/null +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'profile-list'), + ]); + + $request = new GetPaginatedProfilesRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ProfileCollection */ + $profiles = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ProfileCollection::class, $profiles); + $this->assertGreaterThan(0, $profiles->count()); + + foreach ($profiles as $profile) { + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + } + + /** @test */ + public function it_can_iterate_over_profiles() + { + $client = new MockClient([ + GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'profile-list'), + new MockResponse(200, 'empty-list', 'profiles'), + ), + ]); + + $request = (new GetPaginatedProfilesRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $profiles = $response->toResource(); + + foreach ($profiles as $profile) { + $this->assertInstanceOf(Profile::class, $profile); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedProfilesRequest(); + + $this->assertEquals('profiles', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php new file mode 100644 index 00000000..42b9f2d5 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedRefundsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_refunds() + { + $client = new MockClient([ + GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedRefundsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedRefundsRequest(); + + $this->assertEquals('refunds', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php new file mode 100644 index 00000000..08e577f2 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'session-list'), + ]); + + $request = new GetPaginatedSessionsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SessionCollection */ + $sessions = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SessionCollection::class, $sessions); + $this->assertGreaterThan(0, $sessions->count()); + + foreach ($sessions as $session) { + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + } + + /** @test */ + public function it_can_iterate_over_sessions() + { + $client = new MockClient([ + GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'session-list'), + new MockResponse(200, 'empty-list', 'sessions'), + ), + ]); + + $request = (new GetPaginatedSessionsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $sessions = $response->toResource(); + + foreach ($sessions as $session) { + $this->assertInstanceOf(Session::class, $session); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedSessionsRequest(); + + $this->assertEquals('sessions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php new file mode 100644 index 00000000..e8dbdde0 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'capture-list'), + ]); + + $request = new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var CaptureCollection */ + $captures = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertGreaterThan(0, $captures->count()); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_captures() + { + $client = new MockClient([ + GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'capture-list'), + new MockResponse(200, 'empty-list', 'captures'), + ), + ]); + + $request = (new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $captures = $response->toResource(); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementCapturesRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/captures", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php new file mode 100644 index 00000000..87a0838e --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ChargebackCollection */ + $chargebacks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_chargebacks() + { + $client = new MockClient([ + GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'chargeback-list'), + new MockResponse(200, 'empty-list', 'chargebacks'), + ), + ]); + + $request = (new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $chargebacks = $response->toResource(); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementChargebacksRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/chargebacks", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php new file mode 100644 index 00000000..617fc25b --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_payments() + { + $client = new MockClient([ + GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementPaymentsRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php new file mode 100644 index 00000000..dd4679b2 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_refunds() + { + $client = new MockClient([ + GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementRefundsRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/refunds", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php new file mode 100644 index 00000000..c1950528 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'settlement-list'), + ]); + + $request = new GetPaginatedSettlementsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SettlementCollection */ + $settlements = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SettlementCollection::class, $settlements); + $this->assertGreaterThan(0, $settlements->count()); + + foreach ($settlements as $settlement) { + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals('settlement', $settlement->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlements() + { + $client = new MockClient([ + GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'settlement-list'), + new MockResponse(200, 'empty-list', 'settlements'), + ), + ]); + + $request = (new GetPaginatedSettlementsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $settlements = $response->toResource(); + + foreach ($settlements as $settlement) { + $this->assertInstanceOf(Settlement::class, $settlement); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedSettlementsRequest(); + + $this->assertEquals('settlements', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php new file mode 100644 index 00000000..6b7d7748 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -0,0 +1,81 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_subscription_payments() + { + $client = new MockClient([ + GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId); + + $this->assertEquals("customers/{$customerId}/subscriptions/{$subscriptionId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php new file mode 100644 index 00000000..4731b471 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -0,0 +1,80 @@ + new MockResponse(200, 'subscription-list'), + ]); + + $request = new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SubscriptionCollection */ + $subscriptions = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); + $this->assertGreaterThan(0, $subscriptions->count()); + + foreach ($subscriptions as $subscription) { + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertEquals('subscription', $subscription->resource); + } + } + + /** @test */ + public function it_can_iterate_over_subscriptions() + { + $client = new MockClient([ + GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'subscription-list'), + new MockResponse(200, 'empty-list', 'subscriptions'), + ), + ]); + + $request = (new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $subscriptions = $response->toResource(); + + foreach ($subscriptions as $subscription) { + $this->assertInstanceOf(Subscription::class, $subscription); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedSubscriptionsRequest($customerId); + + $this->assertEquals("customers/{$customerId}/subscriptions", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php new file mode 100644 index 00000000..19e1fd61 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'terminal-list'), + ]); + + $request = new GetPaginatedTerminalsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var TerminalCollection */ + $terminals = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(TerminalCollection::class, $terminals); + $this->assertGreaterThan(0, $terminals->count()); + + foreach ($terminals as $terminal) { + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals('terminal', $terminal->resource); + } + } + + /** @test */ + public function it_can_iterate_over_terminals() + { + $client = new MockClient([ + GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'terminal-list'), + new MockResponse(200, 'empty-list', 'terminals'), + ), + ]); + + $request = (new GetPaginatedTerminalsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $terminals = $response->toResource(); + + foreach ($terminals as $terminal) { + $this->assertInstanceOf(Terminal::class, $terminal); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedTerminalsRequest; + + $this->assertEquals('terminals', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentCaptureRequestTest.php b/tests/Http/Requests/GetPaymentCaptureRequestTest.php new file mode 100644 index 00000000..10c3d60a --- /dev/null +++ b/tests/Http/Requests/GetPaymentCaptureRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'capture'), + ]); + + $request = new GetPaymentCaptureRequest('tr_WDqYK6vllg', 'cpt_4qqhO89gsT'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Capture */ + $capture = $response->toResource(); + + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $captureId = 'cpt_4qqhO89gsT'; + $request = new GetPaymentCaptureRequest($paymentId, $captureId); + + $this->assertEquals("payments/{$paymentId}/captures/{$captureId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentChargebackRequestTest.php b/tests/Http/Requests/GetPaymentChargebackRequestTest.php new file mode 100644 index 00000000..116a46e9 --- /dev/null +++ b/tests/Http/Requests/GetPaymentChargebackRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'chargeback'), + ]); + + $request = new GetPaymentChargebackRequest('tr_WDqYK6vllg', 'chb_n9z0tp'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Chargeback */ + $chargeback = $response->toResource(); + + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $chargebackId = 'chb_n9z0tp'; + $request = new GetPaymentChargebackRequest($paymentId, $chargebackId); + + $this->assertEquals("payments/{$paymentId}/chargebacks/{$chargebackId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentLinkRequestTest.php b/tests/Http/Requests/GetPaymentLinkRequestTest.php new file mode 100644 index 00000000..8914a2b8 --- /dev/null +++ b/tests/Http/Requests/GetPaymentLinkRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(200, 'payment-link'), + ]); + + $request = new GetPaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLink */ + $paymentLink = $response->toResource(); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentLinkId = 'pl_4Y0eZitmBnQ5jsBYZIBw'; + $request = new GetPaymentLinkRequest($paymentLinkId); + + $this->assertEquals("payment-links/{$paymentLinkId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php new file mode 100644 index 00000000..cc572e90 --- /dev/null +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'method'), + ]); + + $request = new GetPaymentMethodRequest('ideal'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Method */ + $method = $response->toResource(); + + $this->assertInstanceOf(Method::class, $method); + $this->assertEquals('method', $method->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $methodId = 'ideal'; + $request = new GetPaymentMethodRequest($methodId); + + $this->assertEquals("methods/{$methodId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php new file mode 100644 index 00000000..a90463e7 --- /dev/null +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(200, 'refund'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $refundId = 're_4qqhO89gsT'; + $request = new GetPaymentRefundRequest($paymentId, $refundId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Refund */ + $refund = $response->toResource(); + + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $refundId = 're_4qqhO89gsT'; + $request = new GetPaymentRefundRequest($paymentId, $refundId); + + $this->assertEquals("payments/{$paymentId}/refunds/{$refundId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php new file mode 100644 index 00000000..c1264a67 --- /dev/null +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'payment'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaymentRequest($paymentId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Payment */ + $payment = $response->toResource(); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaymentRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPermissionRequestTest.php b/tests/Http/Requests/GetPermissionRequestTest.php new file mode 100644 index 00000000..dacdf72e --- /dev/null +++ b/tests/Http/Requests/GetPermissionRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'permission'), + ]); + + $request = new GetPermissionRequest('payments.read'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Permission */ + $permission = $response->toResource(); + + $this->assertInstanceOf(Permission::class, $permission); + $this->assertEquals('permission', $permission->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPermissionRequest('payments.read'); + + $this->assertEquals( + 'permissions/payments.read', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetProfileRequestTest.php b/tests/Http/Requests/GetProfileRequestTest.php new file mode 100644 index 00000000..8637aff6 --- /dev/null +++ b/tests/Http/Requests/GetProfileRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'profile'), + ]); + + $request = new GetProfileRequest('pfl_v9hTwCvYqw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Profile */ + $profile = $response->toResource(); + + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetProfileRequest('pfl_v9hTwCvYqw'); + + $this->assertEquals( + 'profiles/pfl_v9hTwCvYqw', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php new file mode 100644 index 00000000..db282976 --- /dev/null +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -0,0 +1,54 @@ + new MockResponse(200, 'session'), + ]); + + $query = new AnyQuery([ + 'testmode' => true, + ]); + + $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Session */ + $session = $response->toResource(); + + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $query = new AnyQuery([ + 'testmode' => true, + ]); + + $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + + $this->assertEquals( + 'sessions/ses_LQNz4v4Qvk', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSettlementRequestTest.php b/tests/Http/Requests/GetSettlementRequestTest.php new file mode 100644 index 00000000..c48d1537 --- /dev/null +++ b/tests/Http/Requests/GetSettlementRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'settlement'), + ]); + + $request = new GetSettlementRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Settlement */ + $settlement = $response->toResource(); + + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals('settlement', $settlement->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetSettlementRequest('stl_jDk30akdN'); + + $this->assertEquals( + 'settlements/stl_jDk30akdN', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSubscriptionRequestTest.php b/tests/Http/Requests/GetSubscriptionRequestTest.php new file mode 100644 index 00000000..5b2b93de --- /dev/null +++ b/tests/Http/Requests/GetSubscriptionRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'subscription'), + ]); + + $request = new GetSubscriptionRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Subscription */ + $subscription = $response->toResource(); + + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertEquals('subscription', $subscription->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetSubscriptionRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); + + $this->assertEquals( + 'customers/cst_kEn1PlbGa/subscriptions/sub_rVKGtNd6s3', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetTerminalRequestTest.php b/tests/Http/Requests/GetTerminalRequestTest.php new file mode 100644 index 00000000..537b80e9 --- /dev/null +++ b/tests/Http/Requests/GetTerminalRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'terminal'), + ]); + + $request = new GetTerminalRequest('term_7MgL4wea'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Terminal */ + $terminal = $response->toResource(); + + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals('terminal', $terminal->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetTerminalRequest('term_7MgL4wea'); + + $this->assertEquals( + 'terminals/term_7MgL4wea', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/ListPermissionsRequestTest.php b/tests/Http/Requests/ListPermissionsRequestTest.php new file mode 100644 index 00000000..7fb0630c --- /dev/null +++ b/tests/Http/Requests/ListPermissionsRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'permission-list'), + ]); + + $request = new ListPermissionsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PermissionCollection */ + $permissions = $response->toResource(); + + $this->assertInstanceOf(PermissionCollection::class, $permissions); + $this->assertGreaterThan(0, $permissions->count()); + + foreach ($permissions as $permission) { + $this->assertInstanceOf(Permission::class, $permission); + $this->assertEquals('permission', $permission->resource); + } + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new ListPermissionsRequest; + + $this->assertEquals('permissions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/PaginatedRequestTest.php b/tests/Http/Requests/PaginatedRequestTest.php new file mode 100644 index 00000000..ac0cc205 --- /dev/null +++ b/tests/Http/Requests/PaginatedRequestTest.php @@ -0,0 +1,53 @@ +assertEquals([], $request->query()->all()); + } + + /** @test */ + public function it_can_handle_query() + { + $query = new ConcreteQuery(['limit' => 10]); + $request = new ConcretePaginatedRequest($query); + + $this->assertEquals(['limit' => 10], $request->query()->all()); + } +} + +class ConcretePaginatedRequest extends PaginatedRequest +{ + public static string $targetResourceClass = BaseCollection::class; + + public function resolveResourcePath(): string + { + return 'test'; + } +} + +class ConcreteQuery extends Query +{ + private array $parameters; + + public function __construct(array $parameters) + { + $this->parameters = $parameters; + } + + public function toArray(): array + { + return $this->parameters; + } +} diff --git a/tests/Http/Requests/ResourceHydratableRequestTest.php b/tests/Http/Requests/ResourceHydratableRequestTest.php new file mode 100644 index 00000000..5e650c7c --- /dev/null +++ b/tests/Http/Requests/ResourceHydratableRequestTest.php @@ -0,0 +1,61 @@ +assertEquals(BaseResource::class, $request->getTargetResourceClass()); + } + + /** @test */ + public function it_can_toggle_auto_hydration() + { + $request = new ConcreteResourceHydratableRequest; + + $this->assertFalse($request->shouldAutoHydrate()); + + ConcreteResourceHydratableRequest::hydrate(true); + $this->assertTrue($request->shouldAutoHydrate()); + + ConcreteResourceHydratableRequest::hydrate(false); + $this->assertFalse($request->shouldAutoHydrate()); + } + + /** @test */ + public function it_throws_exception_when_target_resource_class_is_not_set() + { + $request = new InvalidResourceHydratableRequest; + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Resource class is not set.'); + + $request->getTargetResourceClass(); + } +} + +class ConcreteResourceHydratableRequest extends ResourceHydratableRequest +{ + public static string $targetResourceClass = BaseResource::class; + + public function resolveResourcePath(): string + { + return 'test'; + } +} + +class InvalidResourceHydratableRequest extends ResourceHydratableRequest +{ + public function resolveResourcePath(): string + { + return 'test'; + } +} diff --git a/tests/Http/Requests/RevokeMandateRequestTest.php b/tests/Http/Requests/RevokeMandateRequestTest.php new file mode 100644 index 00000000..f41e7d78 --- /dev/null +++ b/tests/Http/Requests/RevokeMandateRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new RevokeMandateRequest($customerId, $mandateId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new RevokeMandateRequest($customerId, $mandateId); + + $this->assertEquals( + "customers/{$customerId}/mandates/{$mandateId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php new file mode 100644 index 00000000..1ba14083 --- /dev/null +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'customer'), + ]); + + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( + 'Updated Customer Name', + 'updated@example.com', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Customer */ + $customer = $response->toResource(); + + $this->assertInstanceOf(Customer::class, $customer); + $this->assertEquals('customer', $customer->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( + 'Updated Customer Name', + 'updated@example.com', + )); + + $this->assertEquals('customers/cst_kEn1PlbGa', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php new file mode 100644 index 00000000..aeb38ba5 --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'payment-link'), + ]); + + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( + 'Updated payment link', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLink */ + $paymentLink = $response->toResource(); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( + 'Updated payment link', + )); + + $this->assertEquals('payment-links/pl_4Y0eZitmBnQ5jsBYZIBw', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php new file mode 100644 index 00000000..94805f3f --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'payment'), + ]); + + $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + 'Updated payment description', + 'https://example.com/redirect', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Payment */ + $payment = $response->toResource(); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + 'Updated payment description', + 'https://example.com/redirect', + )); + + $this->assertEquals('payments/tr_WDqYK6vllg', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php new file mode 100644 index 00000000..a410da74 --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'route'), + ]); + + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( + new DateTime('2024-01-01'), + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Route */ + $route = $response->toResource(); + + $this->assertInstanceOf(Route::class, $route); + $this->assertEquals('route', $route->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( + new DateTime('2024-01-01'), + )); + + $this->assertEquals('payments/tr_WDqYK6vllg/routes/rt_H2wvxEyQcP', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php new file mode 100644 index 00000000..94071d24 --- /dev/null +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(200, 'profile'), + ]); + + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( + 'Updated Profile Name', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Profile */ + $profile = $response->toResource(); + + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( + 'Updated Profile Name', + )); + + $this->assertEquals('profiles/pfl_v9hTwCvYqw', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php new file mode 100644 index 00000000..cdae6c84 --- /dev/null +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -0,0 +1,51 @@ + new MockResponse(200, 'session'), + ]); + + $payload = new AnyPayload([ + 'status' => 'completed', + 'metadata' => [ + 'order_id' => '12345', + ], + ]); + + $request = new UpdateSessionRequest('ses_LQNz4v4Qvk', $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Session */ + $session = $response->toResource(); + + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $sessionId = 'ses_LQNz4v4Qvk'; + $request = new UpdateSessionRequest($sessionId, new AnyPayload()); + + $this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php new file mode 100644 index 00000000..cb27e5aa --- /dev/null +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -0,0 +1,60 @@ + new MockResponse(200, 'subscription'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + + $money = new Money('EUR', '20.00'); + $payload = new UpdateSubscriptionPayload( + $money, + 'Updated subscription', + '1 month' + ); + + $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, $payload); + + $this->assertEquals( + "customers/{$customerId}/subscriptions/{$subscriptionId}", + $request->resolveResourcePath() + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, new UpdateSubscriptionPayload( + new Money('EUR', '20.00'), + 'Updated subscription', + '1 month' + )); + + $this->assertEquals("customers/{$customerId}/subscriptions/{$subscriptionId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 3500064c..848837f9 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -30,8 +30,6 @@ public function can_get_next_collection_result_when_next_link_is_available() ]) ); - $collection->setAutoHydrate(); - $this->assertTrue($collection->hasNext()); $nextPage = $collection->next(); @@ -49,8 +47,6 @@ public function test_will_return_null_if_no_next_result_is_available() (object) [] ); - $collection->setAutoHydrate(); - $this->assertFalse($collection->hasNext()); $this->assertNull($collection->next()); } @@ -71,8 +67,6 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av ]) ); - $collection->setAutoHydrate(); - $this->assertTrue($collection->hasPrevious()); $previousPage = $collection->previous(); @@ -90,8 +84,6 @@ public function test_will_return_null_if_no_previous_result_is_available() (object) [] ); - $collection->setAutoHydrate(); - $this->assertFalse($collection->hasPrevious()); $this->assertNull($collection->previous()); } @@ -106,8 +98,6 @@ public function test_auto_paginator_returns_lazy_collection() (object) [] ); - $collection->setAutoHydrate(); - $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); } @@ -131,12 +121,12 @@ public function test_auto_paginator_can_handle_consecutive_calls() ]) ); - $orderIds = []; - foreach ($collection->getAutoIterator() as $order) { - $orderIds[] = $order->id; + $paymentIds = []; + foreach ($collection->getAutoIterator() as $payment) { + $paymentIds[] = $payment->id; } - $this->assertEquals(['tr_stTC2WHAuF', 'tr_stTC2WHAuS', 'tr_stTC2WHAuB'], $orderIds); + $this->assertEquals(['tr_stTC2WHAuF', 'tr_stTC2WHAuS', 'tr_stTC2WHAuB'], $paymentIds); } /**