|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Client\Product; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Product\Variant; |
|
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\VariantCollection; |
|
9
|
|
|
use LauLamanApps\IzettleApi\Client\Product\VariantParser; |
|
10
|
|
|
use Money\Money; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Ramsey\Uuid\Uuid; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @small |
|
16
|
|
|
*/ |
|
17
|
|
|
final class VariantsParserTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @test |
|
21
|
|
|
* @dataProvider getVariantArrayData |
|
22
|
|
|
*/ |
|
23
|
|
|
public function parseArray(array $data) |
|
24
|
|
|
{ |
|
25
|
|
|
$variantCollection = VariantParser::parseArray($data); |
|
26
|
|
|
|
|
27
|
|
|
self::assertInstanceOf(VariantCollection::class, $variantCollection); |
|
28
|
|
|
|
|
29
|
|
|
$i = 0;// we cannot use the array key here |
|
30
|
|
|
foreach ($variantCollection->getAll() as $variant) { |
|
31
|
|
|
self::assertInstanceOf(Variant::class, $variant); |
|
32
|
|
|
self::assertInstanceOf(Money::class, $variant->getPrice()); |
|
33
|
|
|
self::assertSame($data[$i]['uuid'], (string) $variant->getUuid()); |
|
34
|
|
|
self::assertSame($data[$i]['name'], $variant->getName()); |
|
35
|
|
|
self::assertSame($data[$i]['description'], $variant->getDescription()); |
|
36
|
|
|
self::assertSame($data[$i]['sku'], $variant->getSku()); |
|
37
|
|
|
self::assertSame($data[$i]['barcode'], $variant->getBarcode()); |
|
38
|
|
|
self::assertSame((int) $data[$i]['defaultQuantity'], $variant->getDefaultQuantity()); |
|
39
|
|
|
self::assertSame($data[$i]['unitName'], $variant->getUnitName()); |
|
40
|
|
|
self::assertSame((string) $data[$i]['price']['amount'], $variant->getPrice()->getAmount()); |
|
41
|
|
|
self::assertSame($data[$i]['price']['currencyId'], $variant->getPrice()->getCurrency()->getCode()); |
|
42
|
|
|
self::assertSame((float) $data[$i]['vatPercentage'], $variant->getVatPercentage()); |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
if (is_null($data[$i]['costPrice'])) { |
|
45
|
|
|
self::assertSame($data[$i]['costPrice'], $variant->getCostPrice()); |
|
46
|
|
|
} else { |
|
47
|
|
|
self::assertInstanceOf(Money::class, $variant->getCostPrice()); |
|
48
|
|
|
self::assertSame((string) $data[$i]['costPrice']['amount'], $variant->getCostPrice()->getAmount()); |
|
49
|
|
|
self::assertSame($data[$i]['costPrice']['currencyId'], $variant->getCostPrice()->getCurrency()->getCode()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$i++; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getVariantArrayData(): array |
|
57
|
|
|
{ |
|
58
|
|
|
return [ |
|
59
|
|
|
'single variant' => [ |
|
60
|
|
|
[ |
|
61
|
|
|
[ |
|
62
|
|
|
"uuid" => (string) Uuid::uuid1(), |
|
63
|
|
|
"name" => "a variant name", |
|
64
|
|
|
"description" => 'the variant description', |
|
65
|
|
|
"sku" => null, |
|
66
|
|
|
"barcode" => null, |
|
67
|
|
|
"defaultQuantity" => "1", |
|
68
|
|
|
"unitName" => null, |
|
69
|
|
|
"price" => [ |
|
70
|
|
|
"amount" => 1000, |
|
71
|
|
|
"currencyId" => "EUR", |
|
72
|
|
|
], |
|
73
|
|
|
"costPrice" => null, |
|
74
|
|
|
"vatPercentage" => "6.0", |
|
75
|
|
|
], |
|
76
|
|
|
], |
|
77
|
|
|
], |
|
78
|
|
|
'multiple variant' =>[ |
|
79
|
|
|
[ |
|
80
|
|
|
[ |
|
81
|
|
|
"uuid" => (string) Uuid::uuid1(), |
|
82
|
|
|
"name" => "Variant A", |
|
83
|
|
|
"description" => null, |
|
84
|
|
|
"sku" => 'Prod-VarA', |
|
85
|
|
|
"barcode" => '9782123456803', |
|
86
|
|
|
"defaultQuantity" => "1", |
|
87
|
|
|
"unitName" => null, |
|
88
|
|
|
"price" => [ |
|
89
|
|
|
"amount" => 1200, |
|
90
|
|
|
"currencyId" => "EUR", |
|
91
|
|
|
], |
|
92
|
|
|
"costPrice" => [ |
|
93
|
|
|
"amount" => 700, |
|
94
|
|
|
"currencyId" => "EUR", |
|
95
|
|
|
], |
|
96
|
|
|
"vatPercentage" => "6.0", |
|
97
|
|
|
], |
|
98
|
|
|
], |
|
99
|
|
|
[ |
|
100
|
|
|
[ |
|
101
|
|
|
"uuid" => (string) Uuid::uuid1(), |
|
102
|
|
|
"name" => "Variant B", |
|
103
|
|
|
"description" => null, |
|
104
|
|
|
"sku" => 'Prod-VarB', |
|
105
|
|
|
"barcode" => null, |
|
106
|
|
|
"defaultQuantity" => "1", |
|
107
|
|
|
"unitName" => null, |
|
108
|
|
|
"price" => [ |
|
109
|
|
|
"amount" => 1500, |
|
110
|
|
|
"currencyId" => "EUR", |
|
111
|
|
|
], |
|
112
|
|
|
"costPrice" => [ |
|
113
|
|
|
"amount" => 900, |
|
114
|
|
|
"currencyId" => "EUR", |
|
115
|
|
|
], |
|
116
|
|
|
"vatPercentage" => "6.0", |
|
117
|
|
|
], |
|
118
|
|
|
], |
|
119
|
|
|
], |
|
120
|
|
|
]; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|