|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Product; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Product\Variant; |
|
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\VariantCollection; |
|
9
|
|
|
use Money\Money; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Ramsey\Uuid\Uuid; |
|
12
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** * @small */ |
|
15
|
|
|
final class VariantCollectionTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @test */ |
|
18
|
|
|
public function variantCollection() |
|
19
|
|
|
{ |
|
20
|
|
|
$variant1 = $this->getVariantWithUuid(); |
|
21
|
|
|
$variant2 = $this->getVariantWithUuid(); |
|
22
|
|
|
$variant3 = $this->getVariantWithUuid(); |
|
23
|
|
|
|
|
24
|
|
|
$variantCollection = new VariantCollection([$variant1, $variant2, $variant3]); |
|
25
|
|
|
$variantCollection->add($variant3);// add variant 3 again it should only end up once in the collection |
|
26
|
|
|
|
|
27
|
|
|
//-- Check if collection contains all 3 variants |
|
28
|
|
|
$collection = $variantCollection->getAll(); |
|
29
|
|
|
self::assertEquals(3, count($collection)); |
|
30
|
|
|
self::assertEquals($variant1, $collection[(string) $variant1->getUuid()]); |
|
31
|
|
|
self::assertEquals($variant2, $collection[(string) $variant2->getUuid()]); |
|
32
|
|
|
self::assertEquals($variant3, $collection[(string) $variant3->getUuid()]); |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$variantCollection->remove($variant2); |
|
36
|
|
|
|
|
37
|
|
|
//-- Check if collection does not contains variant 2 but does contain the others |
|
38
|
|
|
$collection = $variantCollection->getAll(); |
|
39
|
|
|
self::assertEquals(2, count($collection)); |
|
40
|
|
|
self::assertEquals($variant1, $collection[(string) $variant1->getUuid()]); |
|
41
|
|
|
self::assertEquals($variant3, $variantCollection->get($variant3->getUuid())); |
|
42
|
|
|
self::assertFalse(array_key_exists((string) $variant2->getUuid(), $collection)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function getVariantWithUuid() |
|
46
|
|
|
{ |
|
47
|
|
|
return Variant::new( |
|
48
|
|
|
null, |
|
49
|
|
|
null, |
|
50
|
|
|
null, |
|
51
|
|
|
null, |
|
52
|
|
|
1, |
|
53
|
|
|
null, |
|
54
|
|
|
Money::EUR(0), |
|
55
|
|
|
null, |
|
56
|
|
|
0.0 |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|