|
| 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\Dunning; |
| 10 | +use Sysix\LexOffice\Tests\TestClient; |
| 11 | + |
| 12 | +class DunningTest extends TestClient |
| 13 | +{ |
| 14 | + public function testGet(): void |
| 15 | + { |
| 16 | + [$api, $stub] = $this->createClientMockObject(Dunning::class); |
| 17 | + |
| 18 | + $response = $stub->get('resource-id'); |
| 19 | + |
| 20 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 21 | + |
| 22 | + $this->assertEquals('GET', $api->getRequest()->getMethod()); |
| 23 | + $this->assertEquals( |
| 24 | + $api->apiUrl . '/v1/dunnings/resource-id', |
| 25 | + $api->getRequest()->getUri()->__toString() |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + public function testPursue(): void |
| 30 | + { |
| 31 | + [$api, $stub] = $this->createClientMockObject(Dunning::class); |
| 32 | + |
| 33 | + $response = $stub->pursue('resource-id', [ |
| 34 | + 'version' => 0 |
| 35 | + ]); |
| 36 | + |
| 37 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 38 | + |
| 39 | + $this->assertEquals('POST', $api->getRequest()->getMethod()); |
| 40 | + $this->assertEquals( |
| 41 | + $api->apiUrl . '/v1/dunnings?precedingSalesVoucherId=resource-id', |
| 42 | + $api->getRequest()->getUri()->__toString() |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public function testDocument(): void |
| 47 | + { |
| 48 | + [$api, $stub] = $this->createClientMockObject(Dunning::class); |
| 49 | + |
| 50 | + $response = $stub->document('resource-id'); |
| 51 | + |
| 52 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 53 | + |
| 54 | + $this->assertEquals('GET', $api->getRequest()->getMethod()); |
| 55 | + $this->assertEquals( |
| 56 | + $api->apiUrl . '/v1/dunnings/resource-id/document', |
| 57 | + $api->getRequest()->getUri()->__toString() |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function testDocumentContent(): void |
| 62 | + { |
| 63 | + [$api, $stub] = $this->createClientMultiMockObject( |
| 64 | + Dunning::class, |
| 65 | + [ |
| 66 | + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), |
| 67 | + new Response() |
| 68 | + ] |
| 69 | + ); |
| 70 | + |
| 71 | + $response = $stub->document('resource-id', true); |
| 72 | + |
| 73 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 74 | + |
| 75 | + $this->assertEquals('GET', $api->getRequest()->getMethod()); |
| 76 | + $this->assertEquals( |
| 77 | + $api->apiUrl . '/v1/files/fake-id', |
| 78 | + $api->getRequest()->getUri()->__toString() |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + public function testFailedDocumentContent(): void |
| 83 | + { |
| 84 | + [$api, $stub] = $this->createClientMultiMockObject( |
| 85 | + Dunning::class, |
| 86 | + [ |
| 87 | + new Response(500), |
| 88 | + new Response() |
| 89 | + ] |
| 90 | + ); |
| 91 | + |
| 92 | + $response = $stub->document('resource-id', true); |
| 93 | + |
| 94 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 95 | + $this->assertEquals(500, $response->getStatusCode()); |
| 96 | + } |
| 97 | +} |
0 commit comments