1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Client\Purchase; |
6
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Image; |
8
|
|
|
use LauLamanApps\IzettleApi\API\Purchase\Product; |
9
|
|
|
use LauLamanApps\IzettleApi\Client\Purchase\ProductBuilder; |
10
|
|
|
use Money\Currency; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @small |
15
|
|
|
*/ |
16
|
|
|
final class ProductBuilderTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
|
public function parseArray() |
22
|
|
|
{ |
23
|
|
|
$data = $this->getProductData(); |
24
|
|
|
|
25
|
|
|
$builder = new ProductBuilder(); |
26
|
|
|
|
27
|
|
|
$products = $builder->buildFromArray($data, new Currency('EUR')); |
28
|
|
|
|
29
|
|
|
foreach ($products as $index => $product) { |
30
|
|
|
self::assertInstanceOf(Product::class, $product); |
31
|
|
|
self::assertSame($data[$index]['unitPrice'], (int) $product->getUnitPrice()->getAmount()); |
32
|
|
|
self::assertSame($data[$index]['rowTaxableAmount'], (int) $product->getRowTaxableAmount()->getAmount()); |
33
|
|
|
self::assertSame($data[$index]['vatPercentage'], $product->getVatPercentage()); |
34
|
|
|
self::assertSame((int) $data[$index]['quantity'], $product->getQuantity()); |
35
|
|
|
self::assertSame($data[$index]['autoGenerated'], $product->isAutoGenerated()); |
36
|
|
|
self::assertSame($data[$index]['libraryProduct'], $product->isLibraryProduct()); |
37
|
|
|
|
38
|
|
|
if (array_key_exists('productUuid', $data[$index])) { |
39
|
|
|
self::assertSame($data[$index]['productUuid'], (string)$product->getProductUuid()); |
40
|
|
|
} |
41
|
|
|
if (array_key_exists('variantUuid', $data[$index])) { |
42
|
|
|
self::assertSame($data[$index]['variantUuid'], (string) $product->getVariantUuid()); |
43
|
|
|
} |
44
|
|
View Code Duplication |
if (array_key_exists('name', $data[$index])) { |
45
|
|
|
self::assertSame($data[$index]['name'], $product->getName()); |
46
|
|
|
} |
47
|
|
View Code Duplication |
if (array_key_exists('variantName', $data[$index])) { |
48
|
|
|
self::assertSame($data[$index]['variantName'], $product->getVariantName()); |
49
|
|
|
} |
50
|
|
|
if (array_key_exists('imageLookupKey', $data[$index])) { |
51
|
|
|
self::assertInstanceOf(Image::class, $product->getImageLookupKey()); |
52
|
|
|
self::assertSame($data[$index]['imageLookupKey'], $product->getImageLookupKey()->getFilename()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function getProductData() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
[ |
61
|
|
|
"quantity" => "1", |
62
|
|
|
"vatPercentage" => 21.0, |
63
|
|
|
"unitPrice" => 100, |
64
|
|
|
"rowTaxableAmount" => 83, |
65
|
|
|
"autoGenerated" => false, |
66
|
|
|
"libraryProduct" => false, |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
"quantity" => "1", |
70
|
|
|
"productUuid" => "3b3565e0-2694-11e7-b983-c70f05a416cd", |
71
|
|
|
"variantUuid" => "56afb320-2694-11e7-b983-c70f05a416cd", |
72
|
|
|
"vatPercentage" => 0.0, |
73
|
|
|
"unitPrice" => 500, |
74
|
|
|
"rowTaxableAmount" => 500, |
75
|
|
|
"name" => "Munten", |
76
|
|
|
"variantName" => "10 munten", |
77
|
|
|
"imageLookupKey" => "Image.jpg", |
78
|
|
|
"autoGenerated" => false, |
79
|
|
|
"libraryProduct" => true |
80
|
|
|
] |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|