-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathApiTest.php
More file actions
134 lines (107 loc) · 5.22 KB
/
ApiTest.php
File metadata and controls
134 lines (107 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
namespace Sysix\LexOffice\Tests;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Sysix\LexOffice\Clients\Article;
use Sysix\LexOffice\Clients\Contact;
use Sysix\LexOffice\Clients\Country;
use Sysix\LexOffice\Clients\CreditNote;
use Sysix\LexOffice\Clients\DeliveryNote;
use Sysix\LexOffice\Clients\DownPaymentInvoice;
use Sysix\LexOffice\Clients\Dunning;
use Sysix\LexOffice\Clients\Event;
use Sysix\LexOffice\Clients\File;
use Sysix\LexOffice\Clients\Invoice;
use Sysix\LexOffice\Clients\OrderConfirmation;
use Sysix\LexOffice\Clients\Payment;
use Sysix\LexOffice\Clients\PaymentCondition;
use Sysix\LexOffice\Clients\PostingCategory;
use Sysix\LexOffice\Clients\PrintLayout;
use Sysix\LexOffice\Clients\Profile;
use Sysix\LexOffice\Clients\Quotation;
use Sysix\LexOffice\Clients\RecurringTemplate;
use Sysix\LexOffice\Clients\Voucher;
use Sysix\LexOffice\Clients\VoucherList;
final class ApiTest extends TestClient
{
public function createApiMockObject(Response $response)
{
$stub = parent::createApiMockObject($response);
$stub->newRequest('GET', '/');
return $stub;
}
public function testClients(): void
{
$stub = $this->createApiMockObject(new Response());
$this->assertInstanceOf(Article::class, $stub->article());
$this->assertInstanceOf(Contact::class, $stub->contact());
$this->assertInstanceOf(Country::class, $stub->country());
$this->assertInstanceOf(CreditNote::class, $stub->creditNote());
$this->assertInstanceOf(DeliveryNote::class, $stub->deliveryNote());
$this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice());
$this->assertInstanceOf(Dunning::class, $stub->dunning());
$this->assertInstanceOf(Event::class, $stub->event());
$this->assertInstanceOf(File::class, $stub->file());
$this->assertInstanceOf(Invoice::class, $stub->invoice());
$this->assertInstanceOf(OrderConfirmation::class, $stub->orderConfirmation());
$this->assertInstanceOf(Payment::class, $stub->payment());
$this->assertInstanceOf(PaymentCondition::class, $stub->paymentCondition());
$this->assertInstanceOf(PostingCategory::class, $stub->postingCategory());
$this->assertInstanceOf(PrintLayout::class, $stub->printLayout());
$this->assertInstanceOf(Profile::class, $stub->profile());
$this->assertInstanceOf(Quotation::class, $stub->quotation());
$this->assertInstanceOf(RecurringTemplate::class, $stub->recurringTemplate());
$this->assertInstanceOf(Voucher::class, $stub->voucher());
$this->assertInstanceOf(VoucherList::class, $stub->voucherlist());
}
public function testApiUrl(): void
{
$stub = $this->createApiMockObject(
new Response(200, [], 'post-content')
);
$this->assertStringStartsWith('api.lexware.io', $stub->getRequest()->getUri()->getHost());
$stub->apiUrl = 'https://test.de';
$stub->newRequest('POST', 'post-content');
$this->assertStringStartsWith('test.de', $stub->getRequest()->getUri()->getHost());
}
public function testGetSuccessResponse(): void
{
$stub = $this->createApiMockObject(new Response(200, [], 'response-body'));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
}
/**
* @see https://developers.lexoffice.io/docs/#error-codes
*/
public function testGetFailedResponse(): void
{
$stub = $this->createApiMockObject(new Response(401, [], '{"message":"Unauthorized"}'));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
$stub = $this->createApiMockObject(new Response(403, [], '{"message":"\'{accessToken}\' not a valid key=value pair (missing equal-sign) in Authorization header: \'Bearer {accessToken}\'."}'));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
$stub = $this->createApiMockObject(new Response(500, [], '{"message":null}'));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
$stub = $this->createApiMockObject(new Response(503, [], null));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
$stub = $this->createApiMockObject(new Response(504, [], '{"message":"Endpoint request timed out}'));
$response = $stub->getResponse();
$this->assertInstanceOf(ResponseInterface::class, $response);
}
public function testRequestHeaders(): void
{
$api = $this->createApiMockObject(
new Response(200, [], 'post-content')
);
$this->assertCount(1, $api->getRequest()->getHeader('Authorization'));
$this->assertEquals('application/json', $api->getRequest()->getHeaderLine('Accept'));
$api->newRequest('POST', '/');
$this->assertEquals('application/json', $api->getRequest()->getHeaderLine('Content-Type'));
$api->newRequest('PUT', '/');
$this->assertEquals('application/json', $api->getRequest()->getHeaderLine('Content-Type'));
}
}