Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Dec 6, 2023
1 parent 216b627 commit a6e6e8a
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Clients/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class Event extends BaseClient
{
use DeleteTrait;
use CreateTrait;
use DeleteTrait;

protected string $resource = 'event-subscriptions';

Expand Down
2 changes: 1 addition & 1 deletion src/Clients/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

class Invoice extends BaseClient
{
use CreateFinalizeTrait;
use GetTrait;
use VoucherListTrait;
use DocumentClientTrait;
use CreateFinalizeTrait;

protected string $resource = 'invoices';

Expand Down
2 changes: 1 addition & 1 deletion src/Clients/OrderConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class OrderConfirmation extends BaseClient
{
use CreateTrait;
use GetTrait;
use VoucherListTrait;
use CreateTrait;
use DocumentClientTrait;

protected string $resource = 'order-confirmations';
Expand Down
2 changes: 1 addition & 1 deletion src/Clients/Quotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

class Quotation extends BaseClient
{
use CreateFinalizeTrait;
use GetTrait;
use VoucherListTrait;
use DocumentClientTrait;
use CreateFinalizeTrait;

protected string $resource = 'quotations';

Expand Down
2 changes: 1 addition & 1 deletion src/PaginationClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/Clients/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 60 additions & 0 deletions tests/Clients/CreditNoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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);
Expand Down
27 changes: 26 additions & 1 deletion tests/Clients/DownPaymentInvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions tests/Clients/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
);
}

}
30 changes: 15 additions & 15 deletions tests/Clients/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
);
}
}
34 changes: 34 additions & 0 deletions tests/Clients/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
17 changes: 17 additions & 0 deletions tests/Clients/OrderConfirmationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion tests/Clients/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions tests/Clients/QuotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit a6e6e8a

Please sign in to comment.