Completed
Pull Request — master (#11)
by Laurens
02:56 queued 01:11
created

CategoryCollectionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 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