|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sysix\LexOffice\Tests\Clients; |
| 6 | + |
| 7 | +use Psr\Http\Message\ResponseInterface; |
| 8 | +use Sysix\LexOffice\Clients\Article; |
| 9 | +use Sysix\LexOffice\Tests\TestClient; |
| 10 | + |
| 11 | +class ArticleTest extends TestClient |
| 12 | +{ |
| 13 | + public function testGetPage(): void |
| 14 | + { |
| 15 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 16 | + |
| 17 | + $response = $client->getPage(0); |
| 18 | + |
| 19 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 20 | + |
| 21 | + $this->assertEquals('GET', $api->getRequest()->getMethod()); |
| 22 | + $this->assertEquals( |
| 23 | + $api->apiUrl . '/v1/articles?page=0&size=100', |
| 24 | + $api->getRequest()->getUri()->__toString() |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + public function testGetPageWithFilters(): void |
| 29 | + { |
| 30 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 31 | + |
| 32 | + $client->articleNumber = 'LXW-BUHA-2024-001'; |
| 33 | + $client->gtin = '9783648170632'; |
| 34 | + $client->type = 'PRODUCT'; |
| 35 | + |
| 36 | + $client->getPage(0); |
| 37 | + |
| 38 | + $this->assertEquals( |
| 39 | + $api->apiUrl . '/v1/articles?page=0&articleNumber=LXW-BUHA-2024-001>in=9783648170632&type=PRODUCT&size=100', |
| 40 | + $api->getRequest()->getUri()->__toString() |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + public function testCreate(): void |
| 45 | + { |
| 46 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 47 | + |
| 48 | + $response = $client->create([ |
| 49 | + 'title' => 'test' |
| 50 | + ]); |
| 51 | + |
| 52 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 53 | + |
| 54 | + $this->assertEquals('POST', $api->getRequest()->getMethod()); |
| 55 | + $this->assertEquals( |
| 56 | + $api->apiUrl . '/v1/articles', |
| 57 | + $api->getRequest()->getUri()->__toString() |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGet(): void |
| 62 | + { |
| 63 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 64 | + |
| 65 | + $response = $client->get('resource-id'); |
| 66 | + |
| 67 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 68 | + |
| 69 | + $this->assertEquals('GET', $api->getRequest()->getMethod()); |
| 70 | + $this->assertEquals( |
| 71 | + $api->apiUrl . '/v1/articles/resource-id', |
| 72 | + $api->getRequest()->getUri()->__toString() |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public function testUpdate(): void |
| 77 | + { |
| 78 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 79 | + |
| 80 | + $response = $client->update('resource-id', []); |
| 81 | + |
| 82 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 83 | + |
| 84 | + $this->assertEquals('PUT', $api->getRequest()->getMethod()); |
| 85 | + $this->assertEquals( |
| 86 | + $api->apiUrl . '/v1/articles/resource-id', |
| 87 | + $api->getRequest()->getUri()->__toString() |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function testDelete(): void |
| 92 | + { |
| 93 | + [$api, $client] = $this->createClientMockObject(Article::class); |
| 94 | + |
| 95 | + $response = $client->delete('resource-id'); |
| 96 | + |
| 97 | + $this->assertInstanceOf(ResponseInterface::class, $response); |
| 98 | + |
| 99 | + $this->assertEquals('DELETE', $api->getRequest()->getMethod()); |
| 100 | + $this->assertEquals( |
| 101 | + $api->apiUrl . '/v1/articles/resource-id', |
| 102 | + $api->getRequest()->getUri()->__toString() |
| 103 | + ); |
| 104 | + } |
| 105 | +} |
0 commit comments