From 7536d600e49517f8cff8c6133ff3da01584a1ff8 Mon Sep 17 00:00:00 2001 From: Marc van der Meulen Date: Thu, 2 Nov 2023 09:32:30 +0100 Subject: [PATCH 1/3] Add quote response to the appropriate methods Also make use of php enums instead of custom ones --- src/Api/DomainsApi.php | 78 +++++++++++++++---- src/Domain/Billable.php | 49 +++++------- src/Domain/DomainQuote.php | 28 +++++++ src/Domain/Enum/BillableActionEnum.php | 53 ++++--------- src/Domain/Quote.php | 31 ++++++++ tests/Clients/DomainsApiRegisterTest.php | 19 +++++ tests/Clients/DomainsApiRenewTest.php | 24 ++++++ tests/Clients/DomainsApiRestoreTest.php | 24 ++++++ tests/Clients/DomainsApiTransferTest.php | 32 ++++++++ tests/Clients/DomainsApiUpdateTest.php | 32 ++++++++ .../Domain/data/domain_registration_quote.php | 19 +++++ tests/Domain/data/domain_renew_quote.php | 19 +++++ tests/Domain/data/domain_restore_quote.php | 19 +++++ tests/Domain/data/domain_transfer_quote.php | 19 +++++ tests/Domain/data/domain_update_quote.php | 19 +++++ 15 files changed, 382 insertions(+), 83 deletions(-) create mode 100644 src/Domain/DomainQuote.php create mode 100644 src/Domain/Quote.php create mode 100644 tests/Domain/data/domain_registration_quote.php create mode 100644 tests/Domain/data/domain_renew_quote.php create mode 100644 tests/Domain/data/domain_restore_quote.php create mode 100644 tests/Domain/data/domain_transfer_quote.php create mode 100644 tests/Domain/data/domain_update_quote.php diff --git a/src/Api/DomainsApi.php b/src/Api/DomainsApi.php index 7effd07..48c8873 100644 --- a/src/Api/DomainsApi.php +++ b/src/Api/DomainsApi.php @@ -3,11 +3,13 @@ namespace SandwaveIo\RealtimeRegister\Api; use DateTime; +use Exception; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; use SandwaveIo\RealtimeRegister\Domain\DomainAvailability; use SandwaveIo\RealtimeRegister\Domain\DomainContactCollection; use SandwaveIo\RealtimeRegister\Domain\DomainDetails; use SandwaveIo\RealtimeRegister\Domain\DomainDetailsCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; use SandwaveIo\RealtimeRegister\Domain\DomainRegistration; use SandwaveIo\RealtimeRegister\Domain\DomainTransferStatus; use SandwaveIo\RealtimeRegister\Domain\DomainZone; @@ -34,6 +36,7 @@ public function list( ?array $parameters = null ): DomainDetailsCollection { $query = []; + if (! is_null($limit)) { $query['limit'] = $limit; } @@ -114,7 +117,7 @@ public function register( ?KeyDataCollection $keyData = null, ?BillableCollection $billables = null, bool $isQuote = false - ): DomainRegistration { + ): DomainRegistration|DomainQuote { $payload = [ 'customer' => $customer, 'registrant' => $registrant, @@ -151,6 +154,10 @@ public function register( 'quote' => $isQuote, ]); + if ($isQuote) { + return DomainQuote::fromArray($response->json()); + } + return DomainRegistration::fromArray($response->json()); } @@ -176,7 +183,7 @@ public function update( ?KeyDataCollection $keyData = null, ?BillableCollection $billables = null, bool $isQuote = false - ): void { + ): DomainQuote|null { $payload = []; if (is_string($registrant)) { @@ -235,12 +242,22 @@ public function update( $payload['billables'] = $billables->toArray(); } - $this->client->post("v2/domains/{$domainName}/update", $payload, [ + $response = $this->client->post("v2/domains/{$domainName}/update", $payload, [ 'quote' => $isQuote, ]); + + if ($isQuote) { + return DomainQuote::fromArray($response->json()); + } + + return null; } - /* @see https://dm.realtimeregister.com/docs/api/domains/update */ + /** + * @see https://dm.realtimeregister.com/docs/api/domains/update + * + * @throws Exception + */ public function transfer( string $domainName, string $customer, @@ -257,7 +274,7 @@ public function transfer( ?KeyDataCollection $keyData = null, ?BillableCollection $billables = null, ?bool $isQuote = null - ): DomainTransferStatus { + ): DomainTransferStatus|DomainQuote { $payload = [ 'customer' => $customer, 'registrant' => $registrant, @@ -311,6 +328,11 @@ public function transfer( $response = $this->client->post("v2/domains/{$domainName}/transfer", $payload, [ 'quote' => $isQuote, ]); + + if ($isQuote) { + return DomainQuote::fromArray($response->json()); + } + return DomainTransferStatus::fromArray($response->json()); } @@ -322,7 +344,11 @@ public function pushTransfer(string $domain, string $recipient): void ]); } - /** @see https://dm.realtimeregister.com/docs/api/domains/transferinfo */ + /** + * @see https://dm.realtimeregister.com/docs/api/domains/transferinfo + * + * @throws Exception + */ public function transferInfo(string $domain, ?string $processId = null): DomainTransferStatus { if (null === $processId) { @@ -330,12 +356,18 @@ public function transferInfo(string $domain, ?string $processId = null): DomainT } else { $endpoint = sprintf('v2/domains/%s/transfer/%s', $domain, $processId); } + $response = $this->client->get($endpoint); + return DomainTransferStatus::fromArray($response->json()); } - /* @see https://dm.realtimeregister.com/docs/api/domains/transferinfo */ - public function renew(string $domain, int $period, ?BillableCollection $billables = null, ?bool $quote = null): DateTime + /** + * @see https://dm.realtimeregister.com/docs/api/domains/transferinfo + * + * @throws Exception + */ + public function renew(string $domain, int $period, ?BillableCollection $billables = null, ?bool $isQuote = null): DateTime|DomainQuote { $payload = [ 'period' => $period, @@ -345,10 +377,14 @@ public function renew(string $domain, int $period, ?BillableCollection $billable $payload['billables'] = $billables; } - $response = $this->client->post("v2/domains/{$domain}/renew", $payload, is_null($quote) ? [] : [ - 'quote' => $quote, + $response = $this->client->post("v2/domains/{$domain}/renew", $payload, is_null($isQuote) ? [] : [ + 'quote' => $isQuote, ]); + if ($isQuote) { + return DomainQuote::fromArray($response->json()); + } + return new DateTime($response->json()['expiryDate']); } @@ -358,9 +394,17 @@ public function delete(string $domain): void $this->client->delete("v2/domains/{$domain}"); } - /** @see https://dm.realtimeregister.com/docs/api/domains/restore */ - public function restore(string $domain, string $reason, ?BillableCollection $billables = null, ?bool $quote = null): DateTime - { + /** + * @see https://dm.realtimeregister.com/docs/api/domains/restore + * + * @throws Exception + */ + public function restore( + string $domain, + string $reason, + ?BillableCollection $billables = null, + ?bool $isQuote = null + ): DateTime|DomainQuote { $payload = [ 'reason' => $reason, ]; @@ -369,10 +413,14 @@ public function restore(string $domain, string $reason, ?BillableCollection $bil $payload['billables'] = $billables; } - $response = $this->client->post("v2/domains/{$domain}/restore", $payload, is_null($quote) ? [] : [ - 'quote' => $quote, + $response = $this->client->post("v2/domains/{$domain}/restore", $payload, is_null($isQuote) ? [] : [ + 'quote' => $isQuote, ]); + if ($isQuote) { + return DomainQuote::fromArray($response->json()); + } + return new DateTime($response->json()['expiryDate']); } } diff --git a/src/Domain/Billable.php b/src/Domain/Billable.php index ac96c09..4c488a0 100644 --- a/src/Domain/Billable.php +++ b/src/Domain/Billable.php @@ -6,40 +6,27 @@ final class Billable implements DomainObjectInterface { - public string $product; - - public string $action; - - public int $quantity; - - public ?int $amount; - - public ?string $providerName; - - private function __construct( - string $product, - string $action, - int $quantity, - ?int $amount, - ?string $providerName + public function __construct( + public readonly string $product, + public readonly BillableActionEnum $action, + public readonly int $quantity, + public readonly ?int $amount, + public readonly ?bool $refundable, + public readonly ?int $total, + public readonly ?string $providerName ) { - $this->product = $product; - $this->action = $action; - $this->quantity = $quantity; - $this->amount = $amount; - $this->providerName = $providerName; } - public static function fromArray(array $data): Billable + public static function fromArray(array $json): Billable { - BillableActionEnum::validate($data['action']); - return new Billable( - $data['product'], - $data['action'], - $data['quantity'], - $data['amount'] ?? null, - $data['providerName'] ?? null + product: $json['product'], + action: BillableActionEnum::from($json['action']), + quantity: $json['quantity'], + amount: $json['amount'] ?? null, + refundable: $json['refundable'] ?? null, + total: $json['total'] ?? null, + providerName: $json['providerName'] ?? null ); } @@ -47,9 +34,11 @@ public function toArray(): array { return array_filter([ 'product' => $this->product, - 'action' => $this->action, + 'action' => $this->action->value, 'quantity' => $this->quantity, 'amount' => $this->amount, + 'refundable' => $this->refundable, + 'total' => $this->total, 'providerName' => $this->providerName, ], function ($x) { return ! is_null($x); diff --git a/src/Domain/DomainQuote.php b/src/Domain/DomainQuote.php new file mode 100644 index 0000000..f463f13 --- /dev/null +++ b/src/Domain/DomainQuote.php @@ -0,0 +1,28 @@ + $this->command, + 'quote' => $this->quote->toArray(), + ]; + } + + public static function fromArray(array $json): DomainQuote + { + return new DomainQuote( + command: $json['command'], + quote: Quote::fromArray($json['quote']) + ); + } +} diff --git a/src/Domain/Enum/BillableActionEnum.php b/src/Domain/Enum/BillableActionEnum.php index 12c9e32..4446041 100644 --- a/src/Domain/Enum/BillableActionEnum.php +++ b/src/Domain/Enum/BillableActionEnum.php @@ -2,43 +2,20 @@ namespace SandwaveIo\RealtimeRegister\Domain\Enum; -class BillableActionEnum extends AbstractEnum +enum BillableActionEnum: string { - const ACTION_CREATE = 'CREATE'; - const ACTION_REQUEST = 'REQUEST'; - const ACTION_TRANSFER = 'TRANSFER'; - const ACTION_RENEW = 'RENEW'; - const ACTION_RESTORE = 'RESTORE'; - const ACTION_TRANSFER_RESTORE = 'TRANSFER_RESTORE'; - const ACTION_UPDATE = 'UPDATE'; - const ACTION_REGISTRANT_CHANGE = 'REGISTRANT_CHANGE'; - const ACTION_LOCAL_CONTACT = 'LOCAL_CONTACT'; - const ACTION_NEGATIVE_MARKUP = 'NEGATIVE_MARKUP'; - const ACTION_PRIVACY_PROTECT = 'PRIVACY_PROTECT'; - const ACTION_EXTRA_WILDCARD = 'EXTRA_WILDCARD'; - const ACTION_EXTRA_DOMAIN = 'EXTRA_DOMAIN'; - const ACTION_REGISTRY_LOCK = 'REGISTRY_LOCK'; - - protected static array $values = [ - BillableActionEnum::ACTION_CREATE, - BillableActionEnum::ACTION_REQUEST, - BillableActionEnum::ACTION_TRANSFER, - BillableActionEnum::ACTION_RENEW, - BillableActionEnum::ACTION_RESTORE, - BillableActionEnum::ACTION_TRANSFER_RESTORE, - BillableActionEnum::ACTION_UPDATE, - BillableActionEnum::ACTION_REGISTRANT_CHANGE, - BillableActionEnum::ACTION_LOCAL_CONTACT, - BillableActionEnum::ACTION_NEGATIVE_MARKUP, - BillableActionEnum::ACTION_PRIVACY_PROTECT, - BillableActionEnum::ACTION_EXTRA_WILDCARD, - BillableActionEnum::ACTION_EXTRA_DOMAIN, - BillableActionEnum::ACTION_REGISTRY_LOCK, - ]; - - /** @param string $value */ - public static function validate($value): void - { - BillableActionEnum::assertValueValid($value); - } + case ACTION_CREATE = 'CREATE'; + case ACTION_REQUEST = 'REQUEST'; + case ACTION_TRANSFER = 'TRANSFER'; + case ACTION_RENEW = 'RENEW'; + case ACTION_RESTORE = 'RESTORE'; + case ACTION_TRANSFER_RESTORE = 'TRANSFER_RESTORE'; + case ACTION_UPDATE = 'UPDATE'; + case ACTION_REGISTRANT_CHANGE = 'REGISTRANT_CHANGE'; + case ACTION_LOCAL_CONTACT = 'LOCAL_CONTACT'; + case ACTION_NEGATIVE_MARKUP = 'NEGATIVE_MARKUP'; + case ACTION_PRIVACY_PROTECT = 'PRIVACY_PROTECT'; + case ACTION_EXTRA_WILDCARD = 'EXTRA_WILDCARD'; + case ACTION_EXTRA_DOMAIN = 'EXTRA_DOMAIN'; + case ACTION_REGISTRY_LOCK = 'REGISTRY_LOCK'; } diff --git a/src/Domain/Quote.php b/src/Domain/Quote.php new file mode 100644 index 0000000..53c1446 --- /dev/null +++ b/src/Domain/Quote.php @@ -0,0 +1,31 @@ + $this->currency, + 'total' => $this->total, + 'billables' => $this->billables->toArray(), + ]; + } + + public static function fromArray(array $json): Quote + { + return new Quote( + currency: $json['currency'], + total: $json['total'], + billables: BillableCollection::fromArray($json['billables']) + ); + } +} diff --git a/tests/Clients/DomainsApiRegisterTest.php b/tests/Clients/DomainsApiRegisterTest.php index 4e8dbbd..d03b329 100644 --- a/tests/Clients/DomainsApiRegisterTest.php +++ b/tests/Clients/DomainsApiRegisterTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; use SandwaveIo\RealtimeRegister\Domain\DomainContactCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; use SandwaveIo\RealtimeRegister\Domain\DomainRegistration; use SandwaveIo\RealtimeRegister\Domain\KeyDataCollection; use SandwaveIo\RealtimeRegister\Domain\Zone; @@ -12,6 +13,24 @@ class DomainsApiRegisterTest extends TestCase { + public function test_register_quote(): void + { + $sdk = MockedClientFactory::makeSdk( + 200, + json_encode(include __DIR__ . '/../Domain/data/domain_registration_quote.php'), + MockedClientFactory::assertRoute('POST', 'v2/domains/example.nl', $this) + ); + + $registration = $sdk->domains->register( + domainName: 'example.nl', + customer: 'test', + registrant: 'John Doe', + isQuote: true + ); + + $this->assertInstanceOf(DomainQuote::class, $registration); + } + public function test_register(): void { $sdk = MockedClientFactory::makeSdk( diff --git a/tests/Clients/DomainsApiRenewTest.php b/tests/Clients/DomainsApiRenewTest.php index 171fc47..35e3eef 100644 --- a/tests/Clients/DomainsApiRenewTest.php +++ b/tests/Clients/DomainsApiRenewTest.php @@ -5,10 +5,34 @@ use DateTime; use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; +use SandwaveIo\RealtimeRegister\Domain\Enum\BillableActionEnum; use SandwaveIo\RealtimeRegister\Tests\Helpers\MockedClientFactory; class DomainsApiRenewTest extends TestCase { + public function test_renew_quote(): void + { + $sdk = MockedClientFactory::makeSdk( + 200, + json_encode(include __DIR__ . '/../Domain/data/domain_renew_quote.php'), + MockedClientFactory::assertRoute('POST', 'v2/domains/example.com/renew', $this) + ); + + $response = $sdk->domains->renew( + domain: 'example.com', + period: 12, + billables: BillableCollection::fromArray([ + include __DIR__ . '/../Domain/data/billable_valid.php', + include __DIR__ . '/../Domain/data/billable_valid.php', + ]), + isQuote: true + ); + + $this->assertInstanceOf(DomainQuote::class, $response); + $this->assertSame(BillableActionEnum::ACTION_RENEW, $response->quote->billables[0]->action); + } + public function test_renew(): void { $sdk = MockedClientFactory::makeSdk( diff --git a/tests/Clients/DomainsApiRestoreTest.php b/tests/Clients/DomainsApiRestoreTest.php index 50c21b8..208476f 100644 --- a/tests/Clients/DomainsApiRestoreTest.php +++ b/tests/Clients/DomainsApiRestoreTest.php @@ -5,10 +5,34 @@ use DateTime; use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; +use SandwaveIo\RealtimeRegister\Domain\Enum\BillableActionEnum; use SandwaveIo\RealtimeRegister\Tests\Helpers\MockedClientFactory; class DomainsApiRestoreTest extends TestCase { + public function test_restore_quote(): void + { + $sdk = MockedClientFactory::makeSdk( + 200, + json_encode(include __DIR__ . '/../Domain/data/domain_restore_quote.php'), + MockedClientFactory::assertRoute('POST', 'v2/domains/example.com/restore', $this) + ); + + $response = $sdk->domains->restore( + domain: 'example.com', + reason: 'just.. because!', + billables: BillableCollection::fromArray([ + include __DIR__ . '/../Domain/data/billable_valid.php', + include __DIR__ . '/../Domain/data/billable_valid.php', + ]), + isQuote: true + ); + + $this->assertInstanceOf(DomainQuote::class, $response); + $this->assertSame(BillableActionEnum::ACTION_RESTORE, $response->quote->billables[0]->action); + } + public function test_restore(): void { $sdk = MockedClientFactory::makeSdk( diff --git a/tests/Clients/DomainsApiTransferTest.php b/tests/Clients/DomainsApiTransferTest.php index 0237dcf..789ddac 100644 --- a/tests/Clients/DomainsApiTransferTest.php +++ b/tests/Clients/DomainsApiTransferTest.php @@ -6,12 +6,44 @@ use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; use SandwaveIo\RealtimeRegister\Domain\DomainContactCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; +use SandwaveIo\RealtimeRegister\Domain\Enum\BillableActionEnum; use SandwaveIo\RealtimeRegister\Domain\KeyDataCollection; use SandwaveIo\RealtimeRegister\Domain\Zone; use SandwaveIo\RealtimeRegister\Tests\Helpers\MockedClientFactory; class DomainsApiTransferTest extends TestCase { + public function test_transfer_quote(): void + { + $sdk = MockedClientFactory::makeSdk( + 200, + json_encode(include __DIR__ . '/../Domain/data/domain_transfer_quote.php'), + MockedClientFactory::assertRoute('POST', 'v2/domains/example.com/transfer', $this) + ); + + $response = $sdk->domains->transfer( + domainName: 'example.com', + customer: 'test', + registrant: 'John Doe', + privacyProtect: false, + period: 12, + authcode: '123123123', + autoRenew: true, + ns: [], + transferContacts: 'test', + designatedAgent: 'OLD', + zone: Zone::fromArray(include __DIR__ . '/../Domain/data/zone_valid.php'), + contacts: DomainContactCollection::fromArray([include __DIR__ . '/../Domain/data/domain_contact_valid.php']), + keyData: KeyDataCollection::fromArray([include __DIR__ . '/../Domain/data/key_data_valid.php']), + billables: BillableCollection::fromArray([include __DIR__ . '/../Domain/data/billable_valid.php']), + isQuote: true, + ); + + $this->assertInstanceOf(DomainQuote::class, $response); + $this->assertSame(BillableActionEnum::ACTION_TRANSFER, $response->quote->billables[0]->action); + } + /** * @throws JsonException */ diff --git a/tests/Clients/DomainsApiUpdateTest.php b/tests/Clients/DomainsApiUpdateTest.php index 3d9de90..f4d6c2b 100644 --- a/tests/Clients/DomainsApiUpdateTest.php +++ b/tests/Clients/DomainsApiUpdateTest.php @@ -5,12 +5,44 @@ use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\BillableCollection; use SandwaveIo\RealtimeRegister\Domain\DomainContactCollection; +use SandwaveIo\RealtimeRegister\Domain\DomainQuote; +use SandwaveIo\RealtimeRegister\Domain\Enum\BillableActionEnum; use SandwaveIo\RealtimeRegister\Domain\KeyDataCollection; use SandwaveIo\RealtimeRegister\Domain\Zone; use SandwaveIo\RealtimeRegister\Tests\Helpers\MockedClientFactory; class DomainsApiUpdateTest extends TestCase { + public function test_transfer_quote(): void + { + $sdk = MockedClientFactory::makeSdk( + 200, + json_encode(include __DIR__ . '/../Domain/data/domain_update_quote.php'), + MockedClientFactory::assertRoute('POST', 'v2/domains/example.com/update', $this) + ); + + $response = $sdk->domains->update( + domainName: 'example.com', + registrant: 'John Doe', + privacyProtect: false, + period: 12, + authcode: '123123123', + languageCode: 'nl', + autoRenew: true, + ns: [], + statuses: ['OK'], + designatedAgent: 'OLD', + zone: Zone::fromArray(include __DIR__ . '/../Domain/data/zone_valid.php'), + contacts: DomainContactCollection::fromArray([include __DIR__ . '/../Domain/data/contact_handle_valid.php']), + keyData: KeyDataCollection::fromArray([include __DIR__ . '/../Domain/data/key_data_valid.php']), + billables: BillableCollection::fromArray([include __DIR__ . '/../Domain/data/billable_valid.php']), + isQuote: true, + ); + + $this->assertInstanceOf(DomainQuote::class, $response); + $this->assertSame(BillableActionEnum::ACTION_UPDATE, $response->quote->billables[0]->action); + } + public function test_update(): void { $sdk = MockedClientFactory::makeSdk( diff --git a/tests/Domain/data/domain_registration_quote.php b/tests/Domain/data/domain_registration_quote.php new file mode 100644 index 0000000..b163af9 --- /dev/null +++ b/tests/Domain/data/domain_registration_quote.php @@ -0,0 +1,19 @@ + 'CreateDomainCommand', + 'quote' => [ + 'currency' => 'EUR', + 'billables' => [ + [ + 'action' => 'CREATE', + 'product' => 'domain_com', + 'quantity' => 1, + 'amount' => 500, + 'refundable' => true, + 'total' => 500, + ], + ], + 'total' => 500, + ], +]; diff --git a/tests/Domain/data/domain_renew_quote.php b/tests/Domain/data/domain_renew_quote.php new file mode 100644 index 0000000..29d2a0c --- /dev/null +++ b/tests/Domain/data/domain_renew_quote.php @@ -0,0 +1,19 @@ + 'RenewDomainCommand', + 'quote' => [ + 'currency' => 'EUR', + 'billables' => [ + [ + 'action' => 'RENEW', + 'product' => 'domain_com', + 'quantity' => 1, + 'amount' => 500, + 'refundable' => true, + 'total' => 500, + ], + ], + 'total' => 500, + ], +]; diff --git a/tests/Domain/data/domain_restore_quote.php b/tests/Domain/data/domain_restore_quote.php new file mode 100644 index 0000000..d86b610 --- /dev/null +++ b/tests/Domain/data/domain_restore_quote.php @@ -0,0 +1,19 @@ + 'RestoreDomainCommand', + 'quote' => [ + 'currency' => 'EUR', + 'billables' => [ + [ + 'action' => 'RESTORE', + 'product' => 'domain_com', + 'quantity' => 1, + 'amount' => 500, + 'refundable' => false, + 'total' => 500, + ], + ], + 'total' => 500, + ], +]; diff --git a/tests/Domain/data/domain_transfer_quote.php b/tests/Domain/data/domain_transfer_quote.php new file mode 100644 index 0000000..2b4beaf --- /dev/null +++ b/tests/Domain/data/domain_transfer_quote.php @@ -0,0 +1,19 @@ + 'TransferDomainCommand', + 'quote' => [ + 'currency' => 'EUR', + 'billables' => [ + [ + 'action' => 'TRANSFER', + 'product' => 'domain_com', + 'quantity' => 1, + 'amount' => 500, + 'refundable' => false, + 'total' => 500, + ], + ], + 'total' => 500, + ], +]; diff --git a/tests/Domain/data/domain_update_quote.php b/tests/Domain/data/domain_update_quote.php new file mode 100644 index 0000000..ac942cd --- /dev/null +++ b/tests/Domain/data/domain_update_quote.php @@ -0,0 +1,19 @@ + 'UpdateDomainCommand', + 'quote' => [ + 'currency' => 'EUR', + 'billables' => [ + [ + 'action' => 'UPDATE', + 'product' => 'domain_com', + 'quantity' => 1, + 'amount' => 500, + 'refundable' => false, + 'total' => 500, + ], + ], + 'total' => 500, + ], +]; From c5c6576f60d99583f4f32f5e8f75ebcd585ed31e Mon Sep 17 00:00:00 2001 From: Marc van der Meulen Date: Thu, 2 Nov 2023 09:40:41 +0100 Subject: [PATCH 2/3] Fix failing test --- tests/Domain/BillableObjectTest.php | 3 ++- tests/Domain/DomainObjectTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Domain/BillableObjectTest.php b/tests/Domain/BillableObjectTest.php index 0347dbd..9a5cbc5 100644 --- a/tests/Domain/BillableObjectTest.php +++ b/tests/Domain/BillableObjectTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\Billable; use SandwaveIo\RealtimeRegister\Exceptions\InvalidArgumentException; +use ValueError; /** * This TestCase is used to test all single Billable Objects. @@ -32,7 +33,7 @@ public static function parserDataSet(): array 'invalid billable action' => [ Billable::class, include __DIR__ . '/data/billable_invalid_action.php', - InvalidArgumentException::class, + ValueError::class, ], ]; } diff --git a/tests/Domain/DomainObjectTest.php b/tests/Domain/DomainObjectTest.php index bd4c8cc..9e128e5 100644 --- a/tests/Domain/DomainObjectTest.php +++ b/tests/Domain/DomainObjectTest.php @@ -37,6 +37,7 @@ use SandwaveIo\RealtimeRegister\Domain\Zone; use SandwaveIo\RealtimeRegister\Exceptions\InvalidArgumentException; use TypeError; +use ValueError; /** * This TestCase is used to test all single Domain Objects. @@ -69,7 +70,7 @@ public static function parserDataSet(): array 'invalid billable (action)' => [ Billable::class, include __DIR__ . '/data/billable_invalid_action.php', - InvalidArgumentException::class, + ValueError::class, ], 'valid contact (all fields)' => [ Contact::class, From 4b9b51b1a687dd78d40d0fe6f576aafabc7ec584 Mon Sep 17 00:00:00 2001 From: Marc van der Meulen Date: Thu, 2 Nov 2023 10:01:19 +0100 Subject: [PATCH 3/3] Remove unused import --- tests/Domain/BillableObjectTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Domain/BillableObjectTest.php b/tests/Domain/BillableObjectTest.php index 9a5cbc5..245c5f1 100644 --- a/tests/Domain/BillableObjectTest.php +++ b/tests/Domain/BillableObjectTest.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; use SandwaveIo\RealtimeRegister\Domain\Billable; -use SandwaveIo\RealtimeRegister\Exceptions\InvalidArgumentException; use ValueError; /**