From a6e6e8a4a98e996615c683aabd369eceb9490d5f Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 00:00:34 +0100 Subject: [PATCH] add missing tests --- src/Clients/Event.php | 2 +- src/Clients/Invoice.php | 2 +- src/Clients/OrderConfirmation.php | 2 +- src/Clients/Quotation.php | 2 +- src/PaginationClient.php | 2 +- tests/Clients/ContactTest.php | 16 +++++++ tests/Clients/CreditNoteTest.php | 60 ++++++++++++++++++++++++ tests/Clients/DownPaymentInvoiceTest.php | 27 ++++++++++- tests/Clients/EventTest.php | 20 ++++---- tests/Clients/FileTest.php | 30 ++++++------ tests/Clients/InvoiceTest.php | 34 ++++++++++++++ tests/Clients/OrderConfirmationTest.php | 17 +++++++ tests/Clients/ProfileTest.php | 1 - tests/Clients/QuotationTest.php | 17 +++++++ tests/Clients/RecurringTemplateTest.php | 3 +- tests/Clients/VoucherListTest.php | 23 ++++++++- tests/Clients/VoucherTest.php | 30 ++++++------ tests/PaginationClientTest.php | 2 +- tests/TestClient.php | 2 +- 19 files changed, 241 insertions(+), 51 deletions(-) diff --git a/src/Clients/Event.php b/src/Clients/Event.php index a862346..6c32d12 100644 --- a/src/Clients/Event.php +++ b/src/Clients/Event.php @@ -10,8 +10,8 @@ class Event extends BaseClient { - use DeleteTrait; use CreateTrait; + use DeleteTrait; protected string $resource = 'event-subscriptions'; diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index d76f452..c29a789 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -10,10 +10,10 @@ class Invoice extends BaseClient { + use CreateFinalizeTrait; use GetTrait; use VoucherListTrait; use DocumentClientTrait; - use CreateFinalizeTrait; protected string $resource = 'invoices'; diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 449b490..0b06f5b 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -10,9 +10,9 @@ class OrderConfirmation extends BaseClient { + use CreateTrait; use GetTrait; use VoucherListTrait; - use CreateTrait; use DocumentClientTrait; protected string $resource = 'order-confirmations'; diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 772262b..6fdd832 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -10,10 +10,10 @@ class Quotation extends BaseClient { + use CreateFinalizeTrait; use GetTrait; use VoucherListTrait; use DocumentClientTrait; - use CreateFinalizeTrait; protected string $resource = 'quotations'; diff --git a/src/PaginationClient.php b/src/PaginationClient.php index cf0fde1..c00a4be 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -23,7 +23,7 @@ protected function buildQueryParams(array $params): string { $params['size'] = $this->size; - return http_build_query(array_filter($params, static fn ($value) => $value !== null)); + return http_build_query($params); } public function getPage(int $page): ResponseInterface diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index fa12d6c..e02edee 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -23,6 +23,22 @@ public function testGetPage(): void ); } + public function testGetPageWithFilters(): void + { + [$api, $client] = $this->createClientMockObject(Contact::class); + + $client->number = 12345; + $client->customer = true; + $client->vendor = false; + + $client->getPage(0); + + $this->assertEquals( + $api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&number=12345&customer=1&vendor=0&size=100', + $api->request->getUri()->__toString() + ); + } + public function testCreate(): void { [$api, $client] = $this->createClientMockObject(Contact::class); diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 19b0af9..444f05a 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -5,10 +5,26 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\CreditNote; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class CreditNoteTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/credit-notes/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testCreate(): void { [$api, $stub] = $this->createClientMockObject(CreditNote::class); @@ -26,6 +42,40 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/credit-notes?finalize=true', + $api->request->getUri()->__toString() + ); + } + + public function testGetPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=creditnote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); @@ -46,6 +96,16 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(CreditNote::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(CreditNote::class); diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index acff019..c416c64 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -3,12 +3,28 @@ namespace Sysix\LexOffice\Tests\Clients; use Psr\Http\Message\ResponseInterface; -use Sysix\LexOffice\Clients\DownPaymentInvoice; use GuzzleHttp\Psr7\Response; +use Sysix\LexOffice\Clients\DownPaymentInvoice; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class DownPaymentInvoiceTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/down-payment-invoices/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); @@ -29,6 +45,15 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index 7b6f164..9e656d4 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -26,34 +26,34 @@ public function testCreate(): void ); } - public function testGetAll(): void + public function testDelete(): void { [$api, $stub] = $this->createClientMockObject(Event::class); - $response = $stub->getAll(); + $response = $stub->delete('resource-id'); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals('DELETE', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/event-subscriptions', + $api->apiUrl . '/v1/event-subscriptions/resource-id', $api->request->getUri()->__toString() - ); + ); } - public function testDelete(): void + public function testGetAll(): void { [$api, $stub] = $this->createClientMockObject(Event::class); - $response = $stub->delete('resource-id'); + $response = $stub->getAll(); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('DELETE', $api->request->getMethod()); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/event-subscriptions/resource-id', + $api->apiUrl . '/v1/event-subscriptions', $api->request->getUri()->__toString() - ); + ); } } diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index 4fc47a3..0f92d09 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -9,6 +9,21 @@ class FileTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(File::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/files/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testUploadNotSupportedExtension(): void { $this->expectException(LexOfficeApiException::class); @@ -83,19 +98,4 @@ public function testUploadSuccess(): void $api->request->getHeaderLine('Content-Type') ); } - - public function testGet(): void - { - [$api, $stub] = $this->createClientMockObject(File::class); - - $response = $stub->get('resource-id'); - - $this->assertInstanceOf(ResponseInterface::class, $response); - - $this->assertEquals('GET', $api->request->getMethod()); - $this->assertEquals( - $api->apiUrl . '/v1/files/resource-id', - $api->request->getUri()->__toString() - ); - } } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index fab4623..bc94aa0 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -27,6 +27,23 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(Invoice::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/invoices?finalize=true', + $api->request->getUri()->__toString() + ); + } + public function testGet(): void { [$api, $stub] = $this->createClientMockObject(Invoice::class); @@ -42,6 +59,23 @@ public function testGet(): void ); } + public function testPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(Invoice::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 7554f0b..21c225b 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -42,6 +42,23 @@ public function testGet(): void ); } + public function testGetPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=orderconfirmation&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 990e678..1f6f30f 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -2,7 +2,6 @@ namespace Sysix\LexOffice\Tests\Clients; -use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Profile; use Sysix\LexOffice\Tests\TestClient; diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 4caa222..aeb861f 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -27,6 +27,23 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(Quotation::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/quotations?finalize=true', + $api->request->getUri()->__toString() + ); + } + public function testGet(): void { [$api, $stub] = $this->createClientMockObject(Quotation::class); diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php index bcbec12..9f09410 100644 --- a/tests/Clients/RecurringTemplateTest.php +++ b/tests/Clients/RecurringTemplateTest.php @@ -29,8 +29,9 @@ public function testGetPage(): void $stub->getPage(0); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'https://api.lexoffice.io/v1/recurring-templates?page=0&size=100', + $api->apiUrl . '/v1/recurring-templates?page=0&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 572e519..c6ccd41 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -2,6 +2,7 @@ namespace Sysix\LexOffice\Tests\Clients; +use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; @@ -23,7 +24,27 @@ public function testGetPage(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'https://api.lexoffice.io/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->request->getUri()->__toString() + ); + } + + public function testGetAll(): void + { + $this->expectDeprecationV1Warning('getAll'); + + [$api, $stub] = $this->createClientMultiMockObject( + VoucherList::class, + [new Response(200, [], '{"content": [], "totalPages": 1}')] + ); + + $response = $stub->getAll(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 831e539..354ffc6 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -42,37 +42,37 @@ public function testGet(): void ); } - public function testGetAll(): void + public function testUpdate(): void { - $this->expectDeprecationV1Warning('getAll'); - - [$api, $stub] = $this->createClientMultiMockObject( - Voucher::class, - [new Response(200, [], '{"content": [], "totalPages": 1}')] - ); + [$api, $stub] = $this->createClientMockObject(Voucher::class); - $response = $stub->getAll(); + $response = $stub->update('resource-id', []); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals('PUT', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=salesinvoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', + $api->apiUrl . '/v1/vouchers/resource-id', $api->request->getUri()->__toString() ); } - public function testUpdate(): void + public function testGetAll(): void { - [$api, $stub] = $this->createClientMockObject(Voucher::class); + $this->expectDeprecationV1Warning('getAll'); - $response = $stub->update('resource-id', []); + [$api, $stub] = $this->createClientMultiMockObject( + Voucher::class, + [new Response(200, [], '{"content": [], "totalPages": 1}')] + ); + + $response = $stub->getAll(); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('PUT', $api->request->getMethod()); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/vouchers/resource-id', + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=salesinvoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index 44a04fe..d689221 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -86,7 +86,7 @@ public function testGetPage(): void $stub->getPage(0); $this->assertEquals( - 'https://api.lexoffice.io/v1/resource?page=0&size=100', + $api->apiUrl . '/v1/resource?page=0&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/TestClient.php b/tests/TestClient.php index d03b6cc..69996d0 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -53,7 +53,7 @@ public function createApiMultiMockObject(array $responses) * @param class-string $className * @return array{0: Api&MockObject, 1: T&MockObject} */ - public function createClientMockObject(string $className) + public function createClientMockObject(string $className): array { return $this->createClientMultiMockObject($className, [new Response()]); }