Completed
Pull Request — master (#76)
by Julien
02:49
created

testSerializeEntityWithoutIriAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 38
nc 1
nop 0
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Mapado\RestClientSdk\Tests\Units\Model;
4
5
use atoum;
6
use DateTime;
7
use libphonenumber\PhoneNumberFormat;
8
use libphonenumber\PhoneNumberUtil;
9
use Mapado\RestClientSdk\Mapping;
10
use Mapado\RestClientSdk\Mapping\Attribute;
11
use Mapado\RestClientSdk\Mapping\ClassMetadata;
12
use Mapado\RestClientSdk\Mapping\Driver\AnnotationDriver;
13
use Mapado\RestClientSdk\Mapping\Relation;
14
use Mapado\RestClientSdk\Tests\Model\Issue46;
15
use Mapado\RestClientSdk\Tests\Model\Issue75;
16
use Mapado\RestClientSdk\Tests\Model\JsonLd;
17
use Mapado\RestClientSdk\UnitOfWork;
18
19
/**
20
 * Class Serializer
21
 *
22
 * @author Julien Deniau <[email protected]>
23
 */
24
class Serializer extends atoum
25
{
26
    /**
27
     * testJsonEncode
28
     */
29
    public function testJsonEncode()
30
    {
31
        $this->createNewInstance();
32
33
        $this
34
            ->given($cart = $this->createCart())
35
            ->then
36
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
37
                    ->isIdenticalTo([
38
                        '@id' => '/v1/carts/8',
39
                        'status' => 'payed',
40
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
41
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
42
                        'cart_items' => [],
43
                        'order' => null,
44
                    ])
45
46
            // reverse the serialization
47
            ->then
48
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
49
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
50
                ->string($cart->getId())
51
                    ->isEqualTo('/v1/carts/8')
52
                ->string($cart->getStatus())
53
                    ->isEqualTo('payed')
54
                ->datetime($cart->getCreatedAt())
55
                    ->isEqualTo(new \DateTime('2015-09-20T12:08:00'))
56
                ->array($cart->getCartItemList())
57
                    ->isEmpty()
58
59
        ;
60
    }
61
62
    /**
63
     * testJsonEncodeRelation
64
     */
65
    public function testJsonEncodeRelationWithLink()
66
    {
67
        $this->createNewInstance();
68
69
        $this
70
            ->given($cart = $this->createCart())
71
                ->and($cartItem = $this->createKnownCartItem())
72
                ->and($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
73
74
            ->then
75
                ->array($data = $this->testedInstance->serialize(
76
                    $cart,
77
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
78
                    ['serializeRelations' => ['cart_items']]
79
                ))
80
                    ->isIdenticalTo([
81
                        '@id' => '/v1/carts/8',
82
                        'status' => 'payed',
83
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
84
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
85
                        'cart_items' => [
86
                            [
87
                                '@id' => '/v1/cart_items/16',
88
                                'amount' => 1,
89
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
90
                                'data' => [
91
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
92
                                    'who' => 'Jane',
93
                                ],
94
                                'cart' => '/v1/carts/8',
95
                                'product' => '/v1/products/10',
96
                                'cartItemDetailList' => [],
97
                            ],
98
                        ],
99
                        'order' => null,
100
                    ])
101
102
            ->then
103
                ->array($data = $this->testedInstance->serialize(
104
                    $cart,
105
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
106
                    ['serializeRelations' => ['cart_items']]
107
                ))
108
                    ->isIdenticalTo([
109
                        '@id' => '/v1/carts/8',
110
                        'status' => 'payed',
111
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
112
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
113
                        'cart_items' => [
114
                            [
115
                                '@id' => '/v1/cart_items/16',
116
                                'amount' => 1,
117
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
118
                                'data' => [
119
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
120
                                    'who' => 'Jane',
121
                                ],
122
                                'cart' => '/v1/carts/8',
123
                                'product' => '/v1/products/10',
124
                                'cartItemDetailList' => [],
125
                            ],
126
                        ],
127
                        'order' => null,
128
                    ])
129
130
            // reverse the serialization
131
            ->then
132
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
133
                ->array($cart->getCartItemList())
134
                    ->size->isEqualTo(1)
135
                ->object($cartItem = current($cart->getCartItemList()))
136
                    ->isInstanceOf(JsonLd\CartItem::class)
137
                ->string($cartItem->getId())
138
                    ->isEqualTo('/v1/cart_items/16')
139
            ;
140
    }
141
142
    /**
143
     * testJsonEncodeRelationWithoutLink
144
     */
145
    public function testJsonEncodeRelationWithoutLink()
146
    {
147
        $this->createNewInstance();
148
149
        $this
150
            ->given($cart = $this->createCart())
151
                ->and($cartItem = $this->createNewCartItem())
152
                ->and($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
153
            ->then
154
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
155
                    ->isIdenticalTo([
156
                        '@id' => '/v1/carts/8',
157
                        'status' => 'payed',
158
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
159
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
160
                        'cart_items' => [
161
                            [
162
                                'amount' => 2,
163
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
164
                                'data' => [
165
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
166
                                    'who' => 'John',
167
                                ],
168
                                'product' => '/v1/products/10',
169
                                'cartItemDetailList' => [],
170
                            ],
171
                        ],
172
                        'order' => null,
173
                    ])
174
175
            // reverse the serialization
176
            ->then
177
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
178
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
179
                    ->size->isEqualTo(1)
180
                ->object($cartItemList[0])
181
                    ->isInstanceOf(JsonLd\CartItem::class)
182
                ->variable($cartItemList[0]->getId())
183
                    ->isNull
184
        ;
185
    }
186
187
    public function testSerializeThreeLevel()
188
    {
189
        $this->createNewInstance();
190
191
        $this
192
            ->given($cart = $this->createNewCart())
193
                ->and($cartItem = $this->createNewCartItem())
194
                ->and($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
195
            ->then
196
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
197
                    ->isIdenticalTo([
198
                        'status' => 'payed',
199
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
200
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
201
                        'cart_items' => [
202
                            [
203
                                'amount' => 2,
204
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
205
                                'data' => [
206
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
207
                                    'who' => 'John',
208
                                ],
209
                                'product' => '/v1/products/10',
210
                                'cartItemDetailList' => [],
211
                            ],
212
                        ],
213
                        'order' => null,
214
                    ])
215
        ;
216
    }
217
218
    /**
219
     * testJsonEncodeRelationWithoutLinkMultipleLevel
220
     */
221
    public function testJsonEncodeRelationWithoutLinkMultipleLevel()
222
    {
223
        $this->createNewInstance();
224
        $this
225
            ->given($cart = $this->createCart())
226
                ->and($cartItem = $this->createNewCartItem(false))
227
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
228
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
229
            ->if($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
230
            ->then
231
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
232
                    ->isIdenticalTo([
233
                        '@id' => '/v1/carts/8',
234
                        'status' => 'payed',
235
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
236
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
237
                        'cart_items' => [
238
                            [
239
                                'amount' => 2,
240
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
241
                                'data' => [
242
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
243
                                    'who' => 'John',
244
                                ],
245
                                'cartItemDetailList' => [
246
                                    ['name' => 'Bill'],
247
                                    ['name' => 'Bill'],
248
                                ],
249
                            ],
250
                        ],
251
                        'order' => null,
252
                    ])
253
        ;
254
    }
255
256
    /**
257
     * testJsonEncodeMixRelations
258
     */
259
    public function testJsonEncodeMixRelations()
260
    {
261
        $this->createNewInstance();
262
263
        $this
264
            ->given($cart = $this->createCart())
265
                ->and($cartItem = $this->createNewCartItem())
266
                ->and($knownedCartItem = $this->createKnownCartItem())
267
            ->if($cart->addCartItemList($knownedCartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($knownedCartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
268
                ->and($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
269
            ->then
270
                ->array($data = $this->testedInstance->serialize(
271
                    $cart,
272
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
273
                    ['serializeRelations' => ['cart_items']]
274
                ))
275
                    ->isIdenticalTo([
276
                        '@id' => '/v1/carts/8',
277
                        'status' => 'payed',
278
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
279
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
280
                        'cart_items' => [
281
                            [
282
                                '@id' => '/v1/cart_items/16',
283
                                'amount' => 1,
284
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
285
                                'data' => [
286
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
287
                                    'who' => 'Jane',
288
                                ],
289
                                'cart' => '/v1/carts/8',
290
                                'product' => '/v1/products/10',
291
                                'cartItemDetailList' => [],
292
                            ],
293
                            [
294
                                'amount' => 2,
295
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
296
                                'data' => [
297
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
298
                                    'who' => 'John',
299
                                ],
300
                                'product' => '/v1/products/10',
301
                                'cartItemDetailList' => [],
302
                            ],
303
                        ],
304
                        'order' => null,
305
                    ])
306
307
            // reverse the serialization
308
            ->then
309
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
310
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
311
                    ->size->isEqualTo(2)
312
                ->object($cartItem = $cartItemList[0])
313
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
314
                ->string($cartItem->getId())
315
                    ->isEqualTo('/v1/cart_items/16')
316
                ->object($cartItem = $cartItemList[1])
317
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
318
                ->variable($cartItem->getId())
319
                    ->isNull()
320
        ;
321
    }
322
323
    /**
324
     * testNotAllowedSerialization
325
     */
326
    public function testNotAllowedSerialization()
327
    {
328
        $this->createNewInstance();
329
        $this
330
            ->given($cartItem = $this->createNewCartItem())
331
                ->and($cartItemDetail = $this->createNewCartItemDetail())
332
                ->and($cartItemDetail->setCartItem($cartItem))
333
                ->and($testedInstance = $this->testedInstance)
334
            ->then
335
                ->object($cartItemDetail->getCartItem())
336
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
337
                ->exception(function () use ($testedInstance, $cartItemDetail) {
338
                    $testedInstance->serialize($cartItemDetail, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail');
339
                })
340
                    ->isInstanceOf('Mapado\RestClientSdk\Exception\SdkException')
341
        ;
342
    }
343
344
    /**
345
     * testMultipleLevelSerialization
346
     */
347
    public function testMultipleLevelSerialization()
348
    {
349
        $this->createNewInstance();
350
        $this
351
            ->given($cart = $this->createNewCart())
352
                ->and($cartItem = $this->createNewCartItem())
353
                ->and($cartItem->setCart($cart))
354
            ->then
355
                ->array($this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
356
                    ->isIdenticalTo([
357
                        'status' => 'payed',
358
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
359
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
360
                        'cart_items' => [
361
                            [
362
                                'amount' => 2,
363
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
364
                                'data' => [
365
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
366
                                    'who' => 'John',
367
                                ],
368
                                'product' => '/v1/products/10',
369
                                'cartItemDetailList' => [],
370
                            ],
371
                        ],
372
                        'order' => null,
373
                    ])
374
375
        ;
376
    }
377
378
    /**
379
     * testLinkedUnserialize
380
     */
381
    public function testLinkedUnserialize()
382
    {
383
        $this->createNewInstance();
384
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
385
386
        $this
387
            ->given($data = [
388
                    '@id' => '/v1/carts/8',
389
                    'status' => 'payed',
390
                    'clientPhoneNumber' => $phoneNumberUtil->parse('+330123456789', PhoneNumberFormat::INTERNATIONAL),
391
                    'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
392
                    'cart_items' => [
393
                        [
394
                            '@id' => '/v1/cart_items/16',
395
                            'amount' => 2,
396
                            'createdAt' => (new \DateTime('2015-09-20T12:11:00+00:00'))->format(DateTime::RFC3339),
397
                            'data' => [
398
                                'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
399
                                'who' => 'John',
400
                            ],
401
                            'product' => '/v1/products/10',
402
                            'cartItemDetailList' => [],
403
                        ],
404
                    ],
405
                ])
406
            ->then
407
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
408
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
409
                ->object($cart->getClientPhoneNumber())
410
                    ->isInstanceOf('libphonenumber\PhoneNumber')
411
                ->array($cart->getCartItemList())
412
                    ->size->isEqualTo(1)
413
                ->object($cartItem = current($cart->getCartItemList()))
414
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
415
                ->string($cartItem->getId())
416
                    ->isEqualTo('/v1/cart_items/16')
417
                ->integer($cartItem->getAmount())
418
                    ->isEqualTo(2)
419
                ->datetime($cartItem->getCreatedAt())
420
                    ->isEqualTo(new \DateTime('2015-09-20T12:11:00+00:00'))
421
                ->array($cartItem->getData())
422
                    ->isEqualTo([
423
                        'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
424
                        'who' => 'John',
425
                    ])
426
                ->object($cartItem->getProduct())
427
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Product')
428
                ->string($cartItem->getProduct()->getId())
429
                    ->isEqualTo('/v1/products/10')
430
                ->array($cartItem->getCartItemDetailList())
431
                    ->isEmpty()
432
        ;
433
434
        $this->createNewInstance();
435
        $this
436
            ->given($data = [
437
                    '@id' => '/v1/cart_items/16',
438
                    'amount' => 2,
439
                    'cart' => [
440
                        '@id' => '/v1/carts/10',
441
                        'status' => 'waiting',
442
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
443
                    ],
444
                ])
445
446
            ->then
447
                ->object($cartItem = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'))
448
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
449
                ->object($cart = $cartItem->getCart())
450
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
451
                ->string($cart->getClientPhoneNumber())
452
                    ->isEqualTo('+33 1 23 45 67 89')
453
                ->string($cart->getId())
454
                    ->isEqualTo('/v1/carts/10')
455
                ->string($cart->getStatus())
456
                    ->isEqualTo('waiting')
457
        ;
458
    }
459
460
    public function testSerializeNullValues()
461
    {
462
        $this->createNewInstance();
463
        $this
464
            ->given($cart = $this->createNewCart())
465
                ->and($cart->setStatus(null))
466
                ->and($cart->setOrder(null))
467
            ->then
468
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
469
                    ->isIdenticalTo([
470
                        'status' => null,
471
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
472
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
473
                        'cart_items' => [],
474
                        'order' => null,
475
                    ])
476
        ;
477
    }
478
479
    public function testSerializingAttributeNameDiffThanPropertyName()
480
    {
481
        $this->createNewInstance();
482
        $this
483
            ->given($product = $this->createNewProduct())
484
            ->then
485
                ->array($data = $this->testedInstance->serialize($product, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'))
486
                ->isIdenticalTo([
487
                    'product_value' => 8.2,
488
                    'currency' => 'eur',
489
                ])
490
        ;
491
    }
492
493
    public function testWeirdIdentifier()
494
    {
495
        $mapping = $this->getMapping('weirdId');
496
        $this->createNewInstance($mapping);
497
498
        $this
499
            ->given($cart = $this->createCart())
500
                ->and($cartItem = $this->createKnownCartItem())
501
                ->and($cart->addCartItemList($cartItem))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $cart->addCartItemList($cartItem) targeting Mapado\RestClientSdk\Tes...Cart::addCartItemList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
502
503
            ->then
504
                ->array($data = $this->testedInstance->serialize(
505
                    $cart,
506
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
507
                    ['serializeRelations' => ['cart_items']]
508
                ))
509
                    ->isIdenticalTo([
510
                        'weirdId' => '/v1/carts/8',
511
                        'status' => 'payed',
512
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
513
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
514
                        'cart_items' => [
515
                            [
516
                                'weirdId' => '/v1/cart_items/16',
517
                                'amount' => 1,
518
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
519
                                'data' => [
520
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
521
                                    'who' => 'Jane',
522
                                ],
523
                                'cart' => '/v1/carts/8',
524
                                'product' => '/v1/products/10',
525
                                'cartItemDetailList' => [],
526
                            ],
527
                        ],
528
                        'order' => null,
529
                    ])
530
531
            ->then
532
                ->array($data = $this->testedInstance->serialize(
533
                    $cart,
534
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
535
                    ['serializeRelations' => ['cart_items']]
536
                ))
537
                    ->isIdenticalTo([
538
                        'weirdId' => '/v1/carts/8',
539
                        'status' => 'payed',
540
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
541
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
542
                        'cart_items' => [
543
                            [
544
                                'weirdId' => '/v1/cart_items/16',
545
                                'amount' => 1,
546
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
547
                                'data' => [
548
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
549
                                    'who' => 'Jane',
550
                                ],
551
                                'cart' => '/v1/carts/8',
552
                                'product' => '/v1/products/10',
553
                                'cartItemDetailList' => [],
554
                            ],
555
                        ],
556
                        'order' => null,
557
                    ])
558
559
            // reverse the serialization
560
            ->then
561
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
562
                ->string($cart->getId())
563
                    ->isEqualTo('/v1/carts/8')
564
                ->array($cart->getCartItemList())
565
                    ->size->isEqualTo(1)
566
                // ->object($cartItem = current($cart->getCartItemList()))
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
567
                //     ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
568
                // ->string($cartItem->getId())
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
569
                //     ->isEqualTo('/v1/cart_items/16')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
570
            ;
571
    }
572
573
    public function testDeserializeWithExtraFields()
574
    {
575
        $this->createNewInstance();
576
577
        $this
578
            ->given($data = [
579
                '@foo' => 'bar',
580
                '@id' => '/v1/carts/8',
581
                'status' => 'payed',
582
                'clientPhoneNumber' => '+33 1 23 45 67 89',
583
                'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
584
                'cart_items' => [],
585
                'order' => null,
586
            ])
587
588
            ->then
589
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
590
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
591
        ;
592
    }
593
594
    public function testSerializingIriManyToOne()
595
    {
596
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
597
        $mapping = new Mapping();
598
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue46/'));
599
600
        $section = new Issue46\Section();
601
        $section->setId(46);
602
        $section->setIri('/sections/46');
603
        $section->setTitle('section title');
604
605
        $article = new Issue46\Article();
606
        $article->setSection($section);
607
608
        $this->createNewInstance($mapping);
609
610
        $this
611
            ->then
612
                ->array($this->testedInstance->serialize($article, 'Mapado\RestClientSdk\Tests\Model\Issue46\Article'))
613
                    ->isIdenticalTo([
614
                        'id' => null,
615
                        'section' => '/sections/46',
616
                    ])
617
618
                ->if($article->setIri('/articles/44'))
619
620
                ->array($this->testedInstance
621
                    ->serialize(
622
                        $section,
623
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section'
624
                    ))
625
                ->isIdenticalTo([
626
                    '@id' => '/sections/46',
627
                    'id' => 46,
628
                    'title' => 'section title',
629
                    'articleList' => [
630
                        '/articles/44',
631
                    ],
632
                ])
633
634
                ->array($this->testedInstance
635
                    ->serialize(
636
                        $section,
637
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section',
638
                        ['serializeRelations' => ['articleList']]
639
                    ))
640
                ->isIdenticalTo([
641
                    '@id' => '/sections/46',
642
                    'id' => 46,
643
                    'title' => 'section title',
644
                    'articleList' => [
645
                        [
646
                            '@id' => '/articles/44',
647
                            'id' => null,
648
                            'section' => '/sections/46',
649
                        ],
650
                    ],
651
                ])
652
        ;
653
    }
654
655
    public function testDeserializeEntityWithoutIriAttribute()
656
    {
657
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
658
        $mapping = new Mapping();
659
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
660
661
        $this->createNewInstance($mapping);
662
        $this
663
            ->given($data = [
664
                '@id' => '/v1/articles/8',
665
                'tag' => [
666
                    'name' => 'tag name',
667
                ],
668
            ])
669
670
            ->then
671
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
672
                    ->isInstanceOf(Issue75\Article::class)
673
                ->object($article->getTag())
674
                    ->isInstanceOf(Issue75\Tag::class)
675
676
            ->given($data = [
677
                '@id' => '/v1/articles/8',
678
                'tagList' => [
679
                    [
680
                        'name' => 'tag 1 name',
681
                    ],
682
                    [
683
                        'name' => 'tag 2 name',
684
                    ],
685
                ],
686
            ])
687
688
            ->then
689
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
690
                    ->isInstanceOf(Issue75\Article::class)
691
                ->array($tagList = $article->getTagList())
692
                    ->size->isEqualTo(2)
693
                ->object($tagList[0])
694
                    ->isInstanceOf(Issue75\Tag::class)
695
                ->string($tagList[0]->getName())
696
                    ->isIdenticalTo('tag 1 name')
697
                ->object($tagList[1])
698
                    ->isInstanceOf(Issue75\Tag::class)
699
                ->string($tagList[1]->getName())
700
                    ->isIdenticalTo('tag 2 name')
701
        ;
702
    }
703
704
    public function testSerializeEntityWithoutIriAttribute()
705
    {
706
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
707
        $mapping = new Mapping();
708
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
709
710
        $tag = new Issue75\Tag();
711
        $tag->setName('tag title');
712
713
        $article = new Issue75\Article();
714
        $article->setTitle('article title');
715
        // $article->setTag($tag);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
716
        // $article->setTagList([(new Issue75\Tag())->setName('tag 1')]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
717
718
        $this->createNewInstance($mapping);
719
        $this
720
            ->then
721
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
722
                ->isIdenticalTo([
723
                    'title' => 'article title',
724
                    'tag' => null,
725
                    'tagList' => null,
726
                ])
727
728
            ->if($article->setTag($tag))
0 ignored issues
show
Bug introduced by
Are you sure the usage of $article->setTag($tag) targeting Mapado\RestClientSdk\Tes...sue75\Article::setTag() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
729
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
730
                    ->isIdenticalTo([
731
                        'title' => 'article title',
732
                        'tag' => [
733
                            'name' => 'tag title',
734
                        ],
735
                        'tagList' => null,
736
                    ])
737
738
            ->if($article->setTagList([(new Issue75\Tag())->setName('tag 1')]))
739
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
740
                    ->isIdenticalTo([
741
                        'title' => 'article title',
742
                        'tag' => [
743
                            'name' => 'tag title',
744
                        ],
745
                        'tagList' => [
746
                            ['name' => 'tag 1'],
747
                        ],
748
                    ])
749
750
            ->then
751
                // as tags does not have an Attribute identifier, we ignore the serializeRelations context
752
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class, ['serializeRelations' => ['tag', 'tagList']]))
753
                    ->isIdenticalTo([
754
                        'title' => 'article title',
755
                        'tag' => [
756
                            'name' => 'tag title',
757
                        ],
758
                        'tagList' => [
759
                            ['name' => 'tag 1'],
760
                        ],
761
                    ])
762
        ;
763
    }
764
765
    /**
766
     * getMapping
767
     *
768
     * @return Mapping
769
     */
770
    private function getMapping($idKey = '@id')
771
    {
772
        $mapping = new Mapping('/v1');
773
        $mapping->setMapping([
774
            $this->getCartMetadata($idKey),
775
            $this->getCartItemMetadata($idKey),
776
            $this->getCartItemDetailMetadata($idKey),
777
            $this->getProductMetadata($idKey),
778
        ]);
779
780
        return $mapping;
781
    }
782
783
    /**
784
     * @param string $idKey
785
     */
786
    private function getProductMetadata($idKey)
787
    {
788
        $productMetadata = new ClassMetadata(
789
            'products',
790
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Product',
791
            ''
792
        );
793
794
        $productMetadata->setAttributeList([
795
            new Attribute($idKey, 'id', 'string', true),
796
            new Attribute('product_value', 'value'),
797
            new Attribute('currency'),
798
        ]);
799
800
        return $productMetadata;
801
    }
802
803
    /**
804
     * @param string $idKey
805
     */
806
    private function getCartItemDetailMetadata($idKey)
807
    {
808
        $cartItemDetailMetadata = new ClassMetadata(
809
            'cart_item_details',
810
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail',
811
            ''
812
        );
813
814
        $cartItemDetailMetadata->setRelationList([
815
            new Relation('cartItem', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
816
        ]);
817
        $cartItemDetailMetadata->setAttributeList([
818
            new Attribute($idKey, 'id', 'string', true),
819
            new Attribute('name'),
820
            new Attribute('cartItem'),
821
        ]);
822
823
        return $cartItemDetailMetadata;
824
    }
825
826
    /**
827
     * @param string $idKey
828
     */
829
    private function getCartItemMetadata($idKey)
830
    {
831
        $cartItemMetadata = new ClassMetadata(
832
            'cart_items',
833
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
834
            ''
835
        );
836
837
        $cartItemMetadata->setRelationList([
838
            new Relation('cart', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'),
839
            new Relation('product', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'),
840
            new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'),
841
        ]);
842
        $cartItemMetadata->setAttributeList([
843
            new Attribute($idKey, 'id', 'string', true),
844
            new Attribute('amount'),
845
            new Attribute('createdAt', 'createdAt', 'datetime'),
846
            new Attribute('data'),
847
            new Attribute('cart'),
848
            new Attribute('product'),
849
            new Attribute('cartItemDetailList'),
850
        ]);
851
852
        return $cartItemMetadata;
853
    }
854
855
    /**
856
     * @param string $idKey
857
     */
858
    private function getCartMetadata($idKey)
859
    {
860
        $cartMetadata = new ClassMetadata(
861
            'carts',
862
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
863
            ''
864
        );
865
        $cartMetadata->setAttributeList([
866
            new Attribute($idKey, 'id', 'string', true),
867
            new Attribute('status'),
868
            new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'),
869
            new Attribute('createdAt', 'createdAt', 'datetime'),
870
            new Attribute('cart_items', 'cartItemList'),
871
            new Attribute('order'),
872
        ]);
873
        $cartMetadata->setRelationList([
874
            new Relation('cart_items', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
875
            new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'),
876
        ]);
877
878
        return $cartMetadata;
879
    }
880
881
    /**
882
     * createNewCart
883
     *
884
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
885
     */
886
    private function createNewCart()
887
    {
888
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart();
889
        $cart->setStatus('payed');
890
        $cart->setCreatedAt(new DateTime('2015-09-20 12:08:00'));
891
892
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
893
        $clientPhoneNumber = $phoneNumberUtil->parse('+33123456789', PhoneNumberFormat::INTERNATIONAL);
894
        $cart->setClientPhoneNumber($clientPhoneNumber);
895
896
        return $cart;
897
    }
898
899
    /**
900
     * createCart
901
     *
902
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
903
     */
904
    private function createCart()
905
    {
906
        $cart = $this->createNewCart();
907
        $cart->setId('/v1/carts/8');
908
909
        return $cart;
910
    }
911
912
    /**
913
     * createKnownCartItem
914
     *
915
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
916
     */
917
    private function createKnownCartItem()
918
    {
919
        $cartItem = $this->createNewCartItem();
920
        $cartItem->setId('/v1/cart_items/16');
921
        $cartItem->setAmount(1);
922
        $cartItem->setCreatedAt(new DateTime('2015-11-04 15:13:00'));
923
        $cartItem->setData([
924
            'when' => new DateTime('2015-11-04 15:00:00'),
925
            'who' => 'Jane',
926
        ]);
927
        $cartItem->setCart($this->createCart());
928
929
        return $cartItem;
930
    }
931
932
    /**
933
     * createNewCartItem
934
     *
935
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
936
     */
937
    private function createNewCartItem($addKnownedProduct = true)
938
    {
939
        $cartItem = new \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem();
940
        $cartItem->setAmount(2);
941
        $cartItem->setCreatedAt(new DateTime('2015-09-20 12:11:00'));
942
        $cartItem->setData([
943
            'when' => new DateTime('2015-09-20 15:00:00'),
944
            'who' => 'John',
945
        ]);
946
947
        if ($addKnownedProduct) {
948
            $cartItem->setProduct($this->createKnownedProduct());
949
        }
950
951
        return $cartItem;
952
    }
953
954
    /**
955
     * createNewProduct
956
     *
957
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
958
     */
959
    private function createNewProduct()
960
    {
961
        $product = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product();
962
963
        $product->setValue(8.2);
964
        $product->setCurrency('eur');
965
966
        return $product;
967
    }
968
969
    /**
970
     * createKnownedProduct
971
     *
972
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
973
     */
974
    private function createKnownedProduct()
975
    {
976
        $product = $this->createNewProduct();
977
        $product->setId('/v1/products/10');
0 ignored issues
show
Bug introduced by
'/v1/products/10' of type string is incompatible with the type integer expected by parameter $id of Mapado\RestClientSdk\Tes...JsonLd\Product::setId(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

977
        $product->setId(/** @scrutinizer ignore-type */ '/v1/products/10');
Loading history...
978
979
        return $product;
980
    }
981
982
    private function createNewCartItemDetail()
983
    {
984
        $item = new \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail();
985
986
        $item->setName('Bill');
987
988
        return $item;
989
    }
990
991
    /**
992
     * createNewInstance
993
     *
994
     * @param Mapping $mapping
995
     */
996
    private function createNewInstance($mapping = null)
997
    {
998
        $mapping = $mapping ?: $this->getMapping();
999
        $unitOfWork = new UnitOfWork($mapping);
1000
        $this->newTestedInstance($mapping, $unitOfWork);
1001
1002
        $this->mockGenerator->orphanize('__construct');
1003
        $this->mockGenerator->shuntParentClassCalls();
1004
        $restClient = new \mock\Mapado\RestClientSdk\RestClient();
0 ignored issues
show
Bug introduced by
The type mock\Mapado\RestClientSdk\RestClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1005
        $this->mockGenerator->unshuntParentClassCalls();
1006
        $sdk = new \mock\Mapado\RestClientSdk\SdkClient($restClient, $mapping, $unitOfWork, $this->testedInstance);
0 ignored issues
show
Bug introduced by
The type mock\Mapado\RestClientSdk\SdkClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1007
        $sdk->setFileCachePath(__DIR__ . '/../../cache/');
1008
1009
        $cartRepositoryMock = $this->getCartRepositoryMock($sdk, $restClient, $unitOfWork, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart');
1010
1011
        $this->calling($sdk)->getRepository = function ($modelName) use ($cartRepositoryMock) {
1012
            switch ($modelName) {
1013
                case 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart':
1014
                    return $cartRepositoryMock;
1015
                default:
1016
                    return;
1017
            }
1018
        };
1019
1020
        $this->testedInstance->setSdk($sdk);
1021
    }
1022
1023
    /**
1024
     * @param string $modelName
1025
     * @param UnitOfWork $unitOfWork
1026
     */
1027
    private function getCartRepositoryMock($sdk, $restClient, $unitOfWork, $modelName)
1028
    {
1029
        $repository = new \mock\Mapado\RestClientSdk\EntityRepository(
0 ignored issues
show
Bug introduced by
The type mock\Mapado\RestClientSdk\EntityRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1030
            $sdk,
1031
            $restClient,
1032
            $unitOfWork,
1033
            $modelName
1034
        );
1035
1036
        $_this = $this;
1037
1038
        $this->calling($repository)->find = function ($id) use ($_this) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1038
        $this->calling($repository)->find = function (/** @scrutinizer ignore-unused */ $id) use ($_this) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1039
            return $_this->createCart();
1040
        };
1041
1042
        return $repository;
1043
    }
1044
}
1045