|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sysix\LexOffice\Tests\Clients; |
| 6 | + |
| 7 | +use GuzzleHttp\Psr7\Response; |
| 8 | +use Psr\Http\Message\ResponseInterface; |
| 9 | +use Sysix\LexOffice\Clients\DeliveryNote; |
| 10 | +use Sysix\LexOffice\Clients\VoucherList; |
| 11 | +use Sysix\LexOffice\Tests\TestClient; |
| 12 | + |
| 13 | +class DeliveryNoteTest extends TestClient |
| 14 | +{ |
| 15 | + public function testGet(): void |
| 16 | + { |
| 17 | + [$api, $stub] = $this->createClientMockObject(DeliveryNote::class); |
| 18 | + |
| 19 | + $response = $stub->get('resource-id'); |
| 20 | + |
| 21 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 22 | + |
| 23 | + $this->assertEquals('GET', $api->request->getMethod()); |
| 24 | + $this->assertEquals( |
| 25 | + $api->apiUrl . '/v1/delivery-notes/resource-id', |
| 26 | + $api->request->getUri()->__toString() |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + public function testCreate(): void |
| 31 | + { |
| 32 | + [$api, $stub] = $this->createClientMockObject(DeliveryNote::class); |
| 33 | + |
| 34 | + $response = $stub->create([ |
| 35 | + 'version' => 0 |
| 36 | + ]); |
| 37 | + |
| 38 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 39 | + |
| 40 | + $this->assertEquals('POST', $api->request->getMethod()); |
| 41 | + $this->assertEquals( |
| 42 | + $api->apiUrl . '/v1/delivery-notes', |
| 43 | + $api->request->getUri()->__toString() |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public function testGetPage(): void |
| 48 | + { |
| 49 | + $this->expectDeprecationV1Warning('getPage'); |
| 50 | + |
| 51 | + [$api, $stub] = $this->createClientMockObject(DeliveryNote::class); |
| 52 | + |
| 53 | + $response = $stub->getPage(0); |
| 54 | + |
| 55 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 56 | + |
| 57 | + $this->assertEquals('GET', $api->request->getMethod()); |
| 58 | + $this->assertEquals( |
| 59 | + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=deliverynote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', |
| 60 | + $api->request->getUri()->__toString() |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGetAll(): void |
| 65 | + { |
| 66 | + $this->expectDeprecationV1Warning('getAll'); |
| 67 | + |
| 68 | + [$api, $stub] = $this->createClientMultiMockObject( |
| 69 | + DeliveryNote::class, |
| 70 | + [new Response(200, [], '{"content": [], "totalPages": 1}')] |
| 71 | + ); |
| 72 | + |
| 73 | + $response = $stub->getAll(); |
| 74 | + |
| 75 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 76 | + |
| 77 | + $this->assertEquals('GET', $api->request->getMethod()); |
| 78 | + $this->assertEquals( |
| 79 | + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=deliverynote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', |
| 80 | + $api->request->getUri()->__toString() |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + public function testGetVoucherListClient(): void |
| 85 | + { |
| 86 | + [, $stub] = $this->createClientMockObject(DeliveryNote::class); |
| 87 | + |
| 88 | + $client = $stub->getVoucherListClient(); |
| 89 | + |
| 90 | + $this->assertInstanceOf(VoucherList::class, $client); |
| 91 | + } |
| 92 | + |
| 93 | + public function testDocument(): void |
| 94 | + { |
| 95 | + [$api, $stub] = $this->createClientMockObject(DeliveryNote::class); |
| 96 | + |
| 97 | + $response = $stub->document('resource-id'); |
| 98 | + |
| 99 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 100 | + |
| 101 | + $this->assertEquals('GET', $api->request->getMethod()); |
| 102 | + $this->assertEquals( |
| 103 | + $api->apiUrl . '/v1/delivery-notes/resource-id/document', |
| 104 | + $api->request->getUri()->__toString() |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public function testDocumentContent(): void |
| 109 | + { |
| 110 | + [$api, $stub] = $this->createClientMultiMockObject( |
| 111 | + DeliveryNote::class, |
| 112 | + [ |
| 113 | + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), |
| 114 | + new Response() |
| 115 | + ] |
| 116 | + ); |
| 117 | + |
| 118 | + $response = $stub->document('resource-id', true); |
| 119 | + |
| 120 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 121 | + |
| 122 | + $this->assertEquals('GET', $api->request->getMethod()); |
| 123 | + $this->assertEquals( |
| 124 | + $api->apiUrl . '/v1/files/fake-id', |
| 125 | + $api->request->getUri()->__toString() |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + public function testFailedDocumentContent(): void |
| 130 | + { |
| 131 | + [$api, $stub] = $this->createClientMultiMockObject( |
| 132 | + DeliveryNote::class, |
| 133 | + [ |
| 134 | + new Response(500), |
| 135 | + new Response() |
| 136 | + ] |
| 137 | + ); |
| 138 | + |
| 139 | + $response = $stub->document('resource-id', true); |
| 140 | + |
| 141 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 142 | + $this->assertEquals(500, $response->getStatusCode()); |
| 143 | + } |
| 144 | +} |
0 commit comments