Completed
Pull Request — master (#11)
by Laurens
03:40
created

CategoryCollectionTest::categoryCollection()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Product;
6
7
use LauLamanApps\IzettleApi\API\Product\Category;
8
use LauLamanApps\IzettleApi\API\Product\CategoryCollection;
9
use PHPUnit\Framework\TestCase;
10
use Ramsey\Uuid\Uuid;
11
12
/**
13
 * @small
14
 */
15
final class CategoryCollectionTest extends TestCase
16
{
17
    /** @test */
18
    public function categoryCollection()
19
    {
20
        $category1 = $this->getCategoryWithUuid((string) Uuid::uuid1());
21
        $category2 = $this->getCategoryWithUuid((string) Uuid::uuid1());
22
        $category3 = $this->getCategoryWithUuid((string) Uuid::uuid1());
23
24
        $categoryCollection =  new CategoryCollection([$category1, $category2, $category3]);
25
        $categoryCollection->add($category3);// add category 3 again it should only end up once in the collection
26
27
        //-- Check if collection contains all 3 categories
28
        $collection = $categoryCollection->getAll();
29
        self::assertEquals(3, count($collection));
30
        self::assertEquals($category1, $collection[(string) $category1->getUuid()]);
31
        self::assertEquals($category2, $collection[(string) $category2->getUuid()]);
32
        self::assertEquals($category3, $collection[(string) $category3->getUuid()]);
33
        
34
        $categoryCollection->remove($category2);
35
36
        //-- Check if collection does not contains category 2 but does contain the others
37
        $collection = $categoryCollection->getAll();
38
        self::assertEquals(2, count($collection));
39
        self::assertEquals($category1, $collection[(string) $category1->getUuid()]);
40
        self::assertEquals($category3, $categoryCollection->get($category3->getUuid()));
41
        self::assertFalse(array_key_exists((string) $category2->getUuid(), $collection));
42
    }
43
44
    private function getCategoryWithUuid($name)
45
    {
46
        return Category::new($name);
47
    }
48
}
49