1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Product; |
6
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Image; |
8
|
|
|
use LauLamanApps\IzettleApi\API\ImageCollection; |
9
|
|
|
use LauLamanApps\IzettleApi\API\Product\Discount; |
10
|
|
|
use Money\Money; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Ramsey\Uuid\Uuid; |
13
|
|
|
|
14
|
|
|
/** * @small */ |
15
|
|
|
final class DiscountTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @test |
19
|
|
|
* @dataProvider getDiscountData |
20
|
|
|
*/ |
21
|
|
|
public function new( |
22
|
|
|
string $name, |
23
|
|
|
string $description, |
24
|
|
|
ImageCollection $imageCollection, |
25
|
|
|
? Money $amount = null, |
26
|
|
|
?float $percentage = null, |
27
|
|
|
string $externalReference |
28
|
|
|
): void { |
29
|
|
|
$discount = Discount::new( |
30
|
|
|
$name, |
31
|
|
|
$description, |
32
|
|
|
$imageCollection, |
33
|
|
|
$amount, |
34
|
|
|
$percentage, |
35
|
|
|
$externalReference |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$createData = json_decode($discount->getCreateData(), true); |
39
|
|
|
self::assertTrue(Uuid::isValid($createData['uuid'])); |
40
|
|
|
self::assertSame($name, $createData['name']); |
41
|
|
|
self::assertSame($description, $createData['description']); |
42
|
|
|
self::assertSame($imageCollection->getCreateDataArray(), $createData['imageLookupKeys']); |
43
|
|
|
if ($amount) { |
44
|
|
|
self::assertSame($amount->getAmount(), $createData['amount']['amount']); |
45
|
|
|
self::assertSame($amount->getCurrency()->getCode(), $createData['amount']['currencyId']); |
46
|
|
|
} else { |
47
|
|
|
self::assertSame((string) $percentage, $createData['percentage']); |
48
|
|
|
} |
49
|
|
|
self::assertSame($externalReference, $createData['externalReference']); |
50
|
|
|
self::assertSame($name, $createData['name']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getDiscountData(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
[ |
57
|
|
|
'name1', |
58
|
|
|
'description1', |
59
|
|
|
new ImageCollection(), |
60
|
|
|
Money::EUR(100), |
61
|
|
|
null, |
62
|
|
|
'externalReference1' |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
'name2', |
66
|
|
|
'description2', |
67
|
|
|
new ImageCollection([new Image('file.jpg')]), |
68
|
|
|
null, |
69
|
|
|
10.0, |
70
|
|
|
'externalReference2' |
71
|
|
|
] |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|