1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Client\Product; |
6
|
|
|
|
7
|
|
|
use DateTime; |
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\Category; |
9
|
|
|
use LauLamanApps\IzettleApi\API\Product\CategoryCollection; |
10
|
|
|
use LauLamanApps\IzettleApi\Client\Product\CategoryParser; |
11
|
|
|
use Mockery; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
14
|
|
|
use Ramsey\Uuid\Uuid; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @small |
18
|
|
|
*/ |
19
|
|
|
final class CategoryParserTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
* @dataProvider getProductResponseData |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function createFromResponse(ResponseInterface $response, $data): void |
26
|
|
|
{ |
27
|
|
|
$categories = CategoryParser::createFromResponse($response); |
28
|
|
|
foreach ($categories as $index => $category) { |
29
|
|
|
self::assertInstanceOf(Category::class, $category); |
30
|
|
|
self::assertSame($data[$index]['uuid'], (string) $category->getUuid()); |
31
|
|
|
self::assertSame($data[$index]['name'], $category->getName()); |
32
|
|
|
self::assertSame($data[$index]['etag'], $category->getEtag()); |
33
|
|
|
self::assertEquals(new DateTime($data[$index]['updated']), $category->getUpdatedAt()); |
34
|
|
|
self::assertSame($data[$index]['updatedBy'], (string) $category->getUpdatedBy()); |
35
|
|
|
self::assertEquals(new DateTime($data[$index]['created']), $category->getCreatedAt()); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @test |
41
|
|
|
* @dataProvider getVariantArrayData |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function createFromArray(array $data): void |
44
|
|
|
{ |
45
|
|
|
$categoryCollection = CategoryParser::parseArray($data); |
46
|
|
|
|
47
|
|
|
self::assertInstanceOf(CategoryCollection::class, $categoryCollection); |
48
|
|
|
|
49
|
|
|
$i = 0;// we cannot use the array key here |
50
|
|
|
foreach ($categoryCollection->getAll() as $category) { |
51
|
|
|
self::assertSame($data[$i]['uuid'], (string) $category->getUuid()); |
52
|
|
|
self::assertSame($data[$i]['name'], $category->getName()); |
53
|
|
|
self::assertSame($data[$i]['etag'], $category->getEtag()); |
54
|
|
|
self::assertEquals(new DateTime($data[$i]['updated']), $category->getUpdatedAt()); |
55
|
|
|
self::assertSame($data[$i]['updatedBy'], (string) $category->getUpdatedBy()); |
56
|
|
|
self::assertEquals(new DateTime($data[$i]['created']), $category->getCreatedAt()); |
57
|
|
|
|
58
|
|
|
$i++; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getProductResponseData(): array |
63
|
|
|
{ |
64
|
|
|
$data1 = [[ |
65
|
|
|
'uuid' => (string) Uuid::uuid1(), |
66
|
|
|
'name' => 'category1', |
67
|
|
|
'etag' => 'B1C54B44DB967F4240B59AFA30B1AC5E', |
68
|
|
|
'updated' => '2017-12-06T13:21:59.722+0000', |
69
|
|
|
'updatedBy' => (string) Uuid::uuid1(), |
70
|
|
|
'created' => '2017-12-21T13:12:49.272+0000', |
71
|
|
|
]]; |
72
|
|
|
|
73
|
|
|
$mock1 = Mockery::mock(ResponseInterface::class); |
74
|
|
|
$mock1->shouldReceive('getBody')->andReturnSelf(); |
75
|
|
|
$mock1->shouldReceive('getContents')->andReturn(json_encode( |
76
|
|
|
$data1 |
77
|
|
|
)); |
78
|
|
|
|
79
|
|
|
return [ |
80
|
|
|
'single discount' => [ $mock1, $data1 ], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getVariantArrayData(): array |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
'single variant' => [ |
88
|
|
|
[ |
89
|
|
|
[ |
90
|
|
|
'uuid' => (string) Uuid::uuid1(), |
91
|
|
|
'name' => 'category2', |
92
|
|
|
'etag' => 'B1C54B44DB967F4240B59AFA30B1AC5E', |
93
|
|
|
'updated' => '2017-12-16T13:21:59.722+0000', |
94
|
|
|
'updatedBy' => (string) Uuid::uuid1(), |
95
|
|
|
'created' => '2019-12-28T14:12:49.272+0000', |
96
|
|
|
], |
97
|
|
|
], |
98
|
|
|
], |
99
|
|
|
'multiple variant' =>[ |
100
|
|
|
[ |
101
|
|
|
[ |
102
|
|
|
'uuid' => (string) Uuid::uuid1(), |
103
|
|
|
'name' => 'category3', |
104
|
|
|
'etag' => 'B1C54B44DB967F4240B59AFA30B1AC5E', |
105
|
|
|
'updated' => '2017-10-18T13:21:59.722+0000', |
106
|
|
|
'updatedBy' => (string) Uuid::uuid1(), |
107
|
|
|
'created' => '2018-06-21T13:12:49.272+0000', |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
[ |
111
|
|
|
[ |
112
|
|
|
'uuid' => (string) Uuid::uuid1(), |
113
|
|
|
'name' => 'category4', |
114
|
|
|
'etag' => 'B1C54B44DB967F4240B59AFA30B1AC5E', |
115
|
|
|
'updated' => '2017-05-02T13:21:59.722+0000', |
116
|
|
|
'updatedBy' => (string) Uuid::uuid1(), |
117
|
|
|
'created' => '2014-08-05T13:12:49.272+0000', |
118
|
|
|
], |
119
|
|
|
], |
120
|
|
|
], |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|