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