1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Product; |
6
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\ImageCollection; |
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\CategoryCollection; |
9
|
|
|
use LauLamanApps\IzettleApi\API\Product\Product; |
10
|
|
|
use LauLamanApps\IzettleApi\API\Product\ProductCollection; |
11
|
|
|
use LauLamanApps\IzettleApi\API\Product\VariantCollection; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
final class ProductCollectionTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @test */ |
17
|
|
|
public function productCollection() |
18
|
|
|
{ |
19
|
|
|
$product1 = $this->getProductWithUuid(); |
20
|
|
|
$product2 = $this->getProductWithUuid(); |
21
|
|
|
$product3 = $this->getProductWithUuid(); |
22
|
|
|
|
23
|
|
|
$productCollection = new ProductCollection([$product1, $product2, $product3]); |
24
|
|
|
$productCollection->add($product3);// add product 3 again it should only end up once in the collection |
25
|
|
|
|
26
|
|
|
//-- Check if collection contains all 3 products |
27
|
|
|
$collection = $productCollection->getAll(); |
28
|
|
|
self::assertEquals(3, count($collection)); |
29
|
|
|
self::assertEquals($product1, $collection[(string) $product1->getUuid()]); |
30
|
|
|
self::assertEquals($product2, $collection[(string) $product2->getUuid()]); |
31
|
|
|
self::assertEquals($product3, $collection[(string) $product3->getUuid()]); |
32
|
|
|
|
33
|
|
|
$productCollection->remove($product2); |
34
|
|
|
|
35
|
|
|
//-- Check if collection does not contains product 2 but does contain the others |
36
|
|
|
$collection = $productCollection->getAll(); |
37
|
|
|
self::assertEquals(2, count($collection)); |
38
|
|
|
self::assertEquals($product1, $collection[(string) $product1->getUuid()]); |
39
|
|
|
self::assertEquals($product3, $productCollection->get($product3->getUuid())); |
40
|
|
|
self::assertFalse(array_key_exists((string) $product2->getUuid(), $collection)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function getProductWithUuid(): Product |
44
|
|
|
{ |
45
|
|
|
return Product::new( |
46
|
|
|
'name', |
47
|
|
|
'description', |
48
|
|
|
new CategoryCollection(), |
49
|
|
|
new ImageCollection(), |
50
|
|
|
new VariantCollection() |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|