Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

LibraryParserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 8
dl 0
loc 144
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromResponse() 0 19 1
B getData() 0 118 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit\Client\Product;
6
7
use LauLamanApps\IzettleApi\API\Product\DiscountCollection;
8
use LauLamanApps\IzettleApi\API\Product\ProductCollection;
9
use LauLamanApps\IzettleApi\Client\Product\LibraryParser;
10
use Mockery;
11
use PHPUnit\Framework\TestCase;
12
use Psr\Http\Message\ResponseInterface;
13
use Ramsey\Uuid\Uuid;
14
15
/**
16
 * @small
17
 */
18
final class LibraryParserTest extends TestCase
19
{
20
    /**
21
     * @test
22
     */
23
    public function createFromResponse()
24
    {
25
        $data = $this->getData();
26
        $mockedResponse = Mockery::mock(ResponseInterface::class);
27
        $mockedResponse->shouldReceive('getBody')->andReturnSelf();
28
        $mockedResponse->shouldReceive('getContents')->andReturn(json_encode($data));
29
30
        $library = LibraryParser::createFromResponse($mockedResponse);
31
32
        self::assertSame(count($data['products']), count($library->getProducts()->getAll()));
33
        self::assertSame(count($data['discounts']), count($library->getDiscounts()->getAll()));
34
35
        self::assertInstanceOf(Uuid::class, $library->getFromEventLogUuid());
36
        self::assertInstanceOf(Uuid::class, $library->getUntilEventLogUuid());
37
        self::assertInstanceOf(ProductCollection::class, $library->getProducts());
38
        self::assertInstanceOf(DiscountCollection::class, $library->getDiscounts());
39
        self::assertInstanceOf(ProductCollection::class, $library->getDeletedProducts());
40
        self::assertInstanceOf(DiscountCollection::class, $library->getDeletedDiscounts());
41
    }
42
43
    public function getData(): array
44
    {
45
        return [
46
            'untilEventLogUuid' => (string) Uuid::uuid1(),
47
            'fromEventLogUuid' => (string) Uuid::uuid1(),
48
            'products' => [
49
                1 => [
50
                    'uuid' => (string) Uuid::uuid1(),
51
                    'categories' => [],
52
                    'name' => 'product1',
53
                    'description' => null,
54
                    'imageLookupKeys' => [],
55
                    'variants' => [
56
                        0 => [
57
                            'uuid' => (string) Uuid::uuid1(),
58
                            'name' => 'variant1',
59
                            'description' => null,
60
                            'sku' => null,
61
                            'barcode' => null,
62
                            'defaultQuantity' => '1',
63
                            'unitName' => null,
64
                            'price' => [
65
                                'amount' => 6500,
66
                                'currencyId' => 'EUR',
67
                            ],
68
                            'costPrice' => null,
69
                            'vatPercentage' => '6.0',
70
                        ],
71
                    ],
72
                    'externalReference' => null,
73
                    'etag' => 'CB7F0ABBF719F6A834727BF5FC59323C',
74
                    'updated' => '2017-04-21T13:16:36.166+0000',
75
                    'updatedBy' => (string) Uuid::uuid1(),
76
                    'created' => '2017-04-21T13:16:36.166+0000',
77
                    'unitName' => null,
78
                    'vatPercentage' => '6.0',
79
                ],
80
                4 => [
81
                    'uuid' => (string) Uuid::uuid1(),
82
                    'categories' => [],
83
                    'name' => 'product2',
84
                    'description' => null,
85
                    'imageLookupKeys' => [],
86
                    'variants' => [
87
                        0 => [
88
                            'uuid' => (string) Uuid::uuid1(),
89
                            'name' => 'variant2',
90
                            'description' => null,
91
                            'sku' => null,
92
                            'barcode' => null,
93
                            'defaultQuantity' => '1',
94
                            'unitName' => null,
95
                            'price' => [
96
                                'amount' => 12500,
97
                                'currencyId' => 'EUR',
98
                            ],
99
                            'costPrice' => null,
100
                            'vatPercentage' => '6.0',
101
                        ],
102
                        1 => [
103
                            'uuid' => (string) Uuid::uuid1(),
104
                            'name' => 'variant3',
105
                            'description' => null,
106
                            'sku' => null,
107
                            'barcode' => null,
108
                            'defaultQuantity' => '1',
109
                            'unitName' => null,
110
                            'price' => [
111
                                'amount' => 8000,
112
                                'currencyId' => 'EUR',
113
                            ],
114
                            'costPrice' => null,
115
                            'vatPercentage' => '6.0',
116
                        ],
117
                    ],
118
                    'externalReference' => null,
119
                    'etag' => 'FE0F62AD758BDAF477BDD86ECDA56E07',
120
                    'updated' => '2017-04-21T13:16:46.078+0000',
121
                    'updatedBy' => (string) Uuid::uuid1(),
122
                    'created' => '2017-04-21T13:16:00.273+0000',
123
                    'unitName' => null,
124
                    'vatPercentage' => '6.0',
125
                ],
126
            ],
127
            'discounts' => [
128
                0 => [
129
                    'uuid' => (string) Uuid::uuid1(),
130
                    'name' => 'discount1',
131
                    'description' => 'description1',
132
                    'imageLookupKeys' => [
133
                        0 => 'tomQNcudigYT0a_7MbxCIvMqoPM.jpeg'
134
                    ],
135
                    'amount' => null,
136
                    'percentage' => '80.5',
137
                    'externalReference' => 'none',
138
                    'etag' => '291231A318099EF63621193E8C4197F3',
139
                    'updated' => '2017-10-19T19:24:32.832+0000',
140
                    'updatedBy' => (string) Uuid::uuid1(),
141
                    'created' => '2017-10-19T19:24:32.832+0000',
142
                ],
143
                1 => [
144
                    'uuid' => (string) Uuid::uuid1(),
145
                    'name' => 'discount2',
146
                    'description' => 'description2',
147
                    'imageLookupKeys' => [],
148
                    'amount' => null,
149
                    'percentage' => '80.5',
150
                    'externalReference' => 'none',
151
                    'etag' => 'C4247311FFB2A873379358F95FAD10FD',
152
                    'updated' => '2017-10-19T19:16:40.773+0000',
153
                    'updatedBy' => (string) Uuid::uuid1(),
154
                    'created' => '2017-10-19T19:16:40.773+0000',
155
                ],
156
            ],
157
            'deletedProducts' => [],
158
            'deletedDiscounts' => [],
159
        ];
160
    }
161
}
162