Serializer::testSerializeNullValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\Tests\Units\Model;
6
7
use atoum;
8
use DateTime;
9
use DateTimeImmutable;
10
use libphonenumber\PhoneNumberFormat;
11
use libphonenumber\PhoneNumberUtil;
12
use Mapado\RestClientSdk\Exception\MissingSetterException;
13
use Mapado\RestClientSdk\Mapping;
14
use Mapado\RestClientSdk\Mapping\Attribute;
15
use Mapado\RestClientSdk\Mapping\ClassMetadata;
16
use Mapado\RestClientSdk\Mapping\Driver\AnnotationDriver;
17
use Mapado\RestClientSdk\Mapping\Relation;
18
use Mapado\RestClientSdk\Tests\Model\Issue46;
19
use Mapado\RestClientSdk\Tests\Model\Issue75;
20
use Mapado\RestClientSdk\Tests\Model\Issue80;
21
use Mapado\RestClientSdk\Tests\Model\Issue89;
22
use Mapado\RestClientSdk\Tests\Model\Issue90;
23
use Mapado\RestClientSdk\Tests\Model\JsonLd;
24
use Mapado\RestClientSdk\UnitOfWork;
25
26
/**
27
 * Class Serializer
28
 *
29
 * @author Julien Deniau <[email protected]>
30
 */
31
class Serializer extends atoum
32
{
33
    /**
34
     * @var UnitOfWork
35
     */
36
    private $unitOfWork;
37
38
    /**
39
     * testJsonEncode
40
     */
41
    public function testJsonEncode()
42
    {
43
        $this->createNewInstance();
44
45
        $this
46
            ->given($cart = $this->createCart())
47
            ->then
48
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
49
                    ->isIdenticalTo([
50
                        '@id' => '/v1/carts/8',
51
                        'status' => 'payed',
52
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
53
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
54
                        'cart_items' => [],
55
                        'order' => null,
56
                    ])
57
58
            // reverse the serialization
59
            ->then
60
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
61
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
62
                ->string($cart->getId())
63
                    ->isEqualTo('/v1/carts/8')
64
                ->string($cart->getStatus())
65
                    ->isEqualTo('payed')
66
                ->datetime($cart->getCreatedAt())
67
                    ->isEqualTo(new \DateTime('2015-09-20T12:08:00'))
68
                ->array($cart->getCartItemList())
69
                    ->isEmpty()
70
71
        ;
72
    }
73
74
    /**
75
     * testJsonEncodeRelation
76
     */
77
    public function testJsonEncodeRelationWithLink()
78
    {
79
        $this->createNewInstance();
80
81
        $this
82
            ->given($cart = $this->createCart())
83
                ->and($cartItem = $this->createKnownCartItem())
84
                ->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...
85
86
            ->then
87
                ->array($data = $this->testedInstance->serialize(
88
                    $cart,
89
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
90
                    ['serializeRelations' => ['cart_items']]
91
                ))
92
                    ->isIdenticalTo([
93
                        '@id' => '/v1/carts/8',
94
                        'status' => 'payed',
95
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
96
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
97
                        'cart_items' => [
98
                            [
99
                                '@id' => '/v1/cart_items/16',
100
                                'amount' => 1,
101
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
102
                                'data' => [
103
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
104
                                    'who' => 'Jane',
105
                                ],
106
                                'cart' => '/v1/carts/8',
107
                                'product' => '/v1/products/10',
108
                                'cartItemDetailList' => [],
109
                            ],
110
                        ],
111
                        'order' => null,
112
                    ])
113
114
            ->then
115
                ->array($data = $this->testedInstance->serialize(
116
                    $cart,
117
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
118
                    ['serializeRelations' => ['cart_items']]
119
                ))
120
                    ->isIdenticalTo([
121
                        '@id' => '/v1/carts/8',
122
                        'status' => 'payed',
123
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
124
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
125
                        'cart_items' => [
126
                            [
127
                                '@id' => '/v1/cart_items/16',
128
                                'amount' => 1,
129
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
130
                                'data' => [
131
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
132
                                    'who' => 'Jane',
133
                                ],
134
                                'cart' => '/v1/carts/8',
135
                                'product' => '/v1/products/10',
136
                                'cartItemDetailList' => [],
137
                            ],
138
                        ],
139
                        'order' => null,
140
                    ])
141
142
            // reverse the serialization
143
            ->then
144
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
145
                ->array($cart->getCartItemList())
146
                    ->size->isEqualTo(1)
147
                ->object($cartItem = current($cart->getCartItemList()))
148
                    ->isInstanceOf(JsonLd\CartItem::class)
149
                ->string($cartItem->getId())
150
                    ->isEqualTo('/v1/cart_items/16')
151
            ;
152
    }
153
154
    /**
155
     * testJsonEncodeRelationWithoutLink
156
     */
157
    public function testJsonEncodeRelationWithoutLink()
158
    {
159
        $this->createNewInstance();
160
161
        $this
162
            ->given($cart = $this->createCart())
163
                ->and($cartItem = $this->createNewCartItem())
164
                ->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...
165
            ->then
166
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
167
                    ->isIdenticalTo([
168
                        '@id' => '/v1/carts/8',
169
                        'status' => 'payed',
170
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
171
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
172
                        'cart_items' => [
173
                            [
174
                                'amount' => 2,
175
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
176
                                'data' => [
177
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
178
                                    'who' => 'John',
179
                                ],
180
                                'product' => '/v1/products/10',
181
                                'cartItemDetailList' => [],
182
                            ],
183
                        ],
184
                        'order' => null,
185
                    ])
186
187
            // reverse the serialization
188
            ->then
189
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
190
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
191
                    ->size->isEqualTo(1)
192
                ->object($cartItemList[0])
193
                    ->isInstanceOf(JsonLd\CartItem::class)
194
                ->variable($cartItemList[0]->getId())
195
                    ->isNull
196
        ;
197
    }
198
199
    public function testSerializeThreeLevel()
200
    {
201
        $this->createNewInstance();
202
203
        $this
204
            ->given($cart = $this->createNewCart())
205
                ->and($cartItem = $this->createNewCartItem())
206
                ->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...
207
            ->then
208
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
209
                    ->isIdenticalTo([
210
                        'status' => 'payed',
211
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
212
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
213
                        'cart_items' => [
214
                            [
215
                                'amount' => 2,
216
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
217
                                'data' => [
218
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
219
                                    'who' => 'John',
220
                                ],
221
                                'product' => '/v1/products/10',
222
                                'cartItemDetailList' => [],
223
                            ],
224
                        ],
225
                        'order' => null,
226
                    ])
227
        ;
228
    }
229
230
    /**
231
     * testJsonEncodeRelationWithoutLinkMultipleLevel
232
     */
233
    public function testJsonEncodeRelationWithoutLinkMultipleLevel()
234
    {
235
        $this->createNewInstance();
236
        $this
237
            ->given($cart = $this->createCart())
238
                ->and($cartItem = $this->createNewCartItem(false))
239
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
240
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
241
            ->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...
242
            ->then
243
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
244
                    ->isIdenticalTo([
245
                        '@id' => '/v1/carts/8',
246
                        'status' => 'payed',
247
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
248
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
249
                        'cart_items' => [
250
                            [
251
                                'amount' => 2,
252
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
253
                                'data' => [
254
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
255
                                    'who' => 'John',
256
                                ],
257
                                'cartItemDetailList' => [
258
                                    ['name' => 'Bill'],
259
                                    ['name' => 'Bill'],
260
                                ],
261
                            ],
262
                        ],
263
                        'order' => null,
264
                    ])
265
        ;
266
    }
267
268
    /**
269
     * testJsonEncodeMixRelations
270
     */
271
    public function testJsonEncodeMixRelations()
272
    {
273
        $this->createNewInstance();
274
275
        $this
276
            ->given($cart = $this->createCart())
277
                ->and($cartItem = $this->createNewCartItem())
278
                ->and($knownedCartItem = $this->createKnownCartItem())
279
            ->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...
280
                ->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...
281
            ->then
282
                ->array($data = $this->testedInstance->serialize(
283
                    $cart,
284
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
285
                    ['serializeRelations' => ['cart_items']]
286
                ))
287
                    ->isIdenticalTo([
288
                        '@id' => '/v1/carts/8',
289
                        'status' => 'payed',
290
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
291
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
292
                        'cart_items' => [
293
                            [
294
                                '@id' => '/v1/cart_items/16',
295
                                'amount' => 1,
296
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
297
                                'data' => [
298
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
299
                                    'who' => 'Jane',
300
                                ],
301
                                'cart' => '/v1/carts/8',
302
                                'product' => '/v1/products/10',
303
                                'cartItemDetailList' => [],
304
                            ],
305
                            [
306
                                'amount' => 2,
307
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
308
                                'data' => [
309
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
310
                                    'who' => 'John',
311
                                ],
312
                                'product' => '/v1/products/10',
313
                                'cartItemDetailList' => [],
314
                            ],
315
                        ],
316
                        'order' => null,
317
                    ])
318
319
            // reverse the serialization
320
            ->then
321
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
322
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
323
                    ->size->isEqualTo(2)
324
                ->object($cartItem = $cartItemList[0])
325
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
326
                ->string($cartItem->getId())
327
                    ->isEqualTo('/v1/cart_items/16')
328
                ->object($cartItem = $cartItemList[1])
329
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
330
                ->variable($cartItem->getId())
331
                    ->isNull()
332
        ;
333
    }
334
335
    /**
336
     * testNotAllowedSerialization
337
     */
338
    public function testNotAllowedSerialization()
339
    {
340
        $this->createNewInstance();
341
        $this
342
            ->given($cartItem = $this->createNewCartItem())
343
                ->and($cartItemDetail = $this->createNewCartItemDetail())
344
                ->and($cartItemDetail->setCartItem($cartItem))
345
                ->and($testedInstance = $this->testedInstance)
346
            ->then
347
                ->object($cartItemDetail->getCartItem())
348
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
349
                ->exception(function () use ($testedInstance, $cartItemDetail) {
350
                    $testedInstance->serialize($cartItemDetail, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail');
351
                })
352
                    ->isInstanceOf('Mapado\RestClientSdk\Exception\SdkException')
353
        ;
354
    }
355
356
    /**
357
     * testMultipleLevelSerialization
358
     */
359
    public function testMultipleLevelSerialization()
360
    {
361
        $this->createNewInstance();
362
        $this
363
            ->given($cart = $this->createNewCart())
364
                ->and($cartItem = $this->createNewCartItem())
365
                ->and($cartItem->setCart($cart))
366
            ->then
367
                ->array($this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
368
                    ->isIdenticalTo([
369
                        'status' => 'payed',
370
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
371
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
372
                        'cart_items' => [
373
                            [
374
                                'amount' => 2,
375
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
376
                                'data' => [
377
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
378
                                    'who' => 'John',
379
                                ],
380
                                'product' => '/v1/products/10',
381
                                'cartItemDetailList' => [],
382
                            ],
383
                        ],
384
                        'order' => null,
385
                    ])
386
387
        ;
388
    }
389
390
    /**
391
     * testLinkedUnserialize
392
     */
393
    public function testLinkedUnserialize()
394
    {
395
        $this->createNewInstance();
396
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
397
398
        $this
399
            ->given($data = [
400
                    '@id' => '/v1/carts/8',
401
                    'status' => 'payed',
402
                    'clientPhoneNumber' => $phoneNumberUtil->parse('+330123456789', PhoneNumberFormat::INTERNATIONAL),
403
                    'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
404
                    'cart_items' => [
405
                        [
406
                            '@id' => '/v1/cart_items/16',
407
                            'amount' => 2,
408
                            'createdAt' => (new \DateTime('2015-09-20T12:11:00+00:00'))->format(DateTime::RFC3339),
409
                            'data' => [
410
                                'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
411
                                'who' => 'John',
412
                            ],
413
                            'product' => '/v1/products/10',
414
                            'cartItemDetailList' => [],
415
                        ],
416
                    ],
417
                ])
418
            ->then
419
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
420
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
421
                ->object($cart->getClientPhoneNumber())
422
                    ->isInstanceOf('libphonenumber\PhoneNumber')
423
                ->array($cart->getCartItemList())
424
                    ->size->isEqualTo(1)
425
                ->object($cartItem = current($cart->getCartItemList()))
426
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
427
                ->string($cartItem->getId())
428
                    ->isEqualTo('/v1/cart_items/16')
429
                ->integer($cartItem->getAmount())
430
                    ->isEqualTo(2)
431
                ->datetime($cartItem->getCreatedAt())
432
                    ->isEqualTo(new \DateTime('2015-09-20T12:11:00+00:00'))
433
                ->array($cartItem->getData())
434
                    ->isEqualTo([
435
                        'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
436
                        'who' => 'John',
437
                    ])
438
                ->object($cartItem->getProduct())
439
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Product')
440
                ->string($cartItem->getProduct()->getId())
441
                    ->isEqualTo('/v1/products/10')
442
                ->array($cartItem->getCartItemDetailList())
443
                    ->isEmpty()
444
        ;
445
446
        $this->createNewInstance();
447
        $this
448
            ->given($data = [
449
                    '@id' => '/v1/cart_items/16',
450
                    'amount' => 2,
451
                    'cart' => [
452
                        '@id' => '/v1/carts/10',
453
                        'status' => 'waiting',
454
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
455
                    ],
456
                ])
457
458
            ->then
459
                ->object($cartItem = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'))
460
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
461
                ->object($cart = $cartItem->getCart())
462
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
463
                ->string($cart->getClientPhoneNumber())
464
                    ->isEqualTo('+33 1 23 45 67 89')
465
                ->string($cart->getId())
466
                    ->isEqualTo('/v1/carts/10')
467
                ->string($cart->getStatus())
468
                    ->isEqualTo('waiting')
469
        ;
470
    }
471
472
    public function testSerializeNullValues()
473
    {
474
        $this->createNewInstance();
475
        $this
476
            ->given($cart = $this->createNewCart())
477
                ->and($cart->setStatus(null))
478
                ->and($cart->setOrder(null))
479
            ->then
480
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
481
                    ->isIdenticalTo([
482
                        'status' => null,
483
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
484
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
485
                        'cart_items' => [],
486
                        'order' => null,
487
                    ])
488
        ;
489
    }
490
491
    public function testSerializingAttributeNameDiffThanPropertyName()
492
    {
493
        $this->createNewInstance();
494
        $this
495
            ->given($product = $this->createNewProduct())
496
            ->then
497
                ->array($data = $this->testedInstance->serialize($product, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'))
498
                ->isIdenticalTo([
499
                    'product_value' => 8.2,
500
                    'currency' => 'eur',
501
                ])
502
        ;
503
    }
504
505
    public function testWeirdIdentifier()
506
    {
507
        $mapping = $this->getMapping('weirdId');
508
        $this->createNewInstance($mapping);
509
510
        $this
511
            ->given($cart = $this->createCart())
512
                ->and($cartItem = $this->createKnownCartItem())
513
                ->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...
514
515
            ->then
516
                ->array($data = $this->testedInstance->serialize(
517
                    $cart,
518
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
519
                    ['serializeRelations' => ['cart_items']]
520
                ))
521
                    ->isIdenticalTo([
522
                        'weirdId' => '/v1/carts/8',
523
                        'status' => 'payed',
524
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
525
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
526
                        'cart_items' => [
527
                            [
528
                                'weirdId' => '/v1/cart_items/16',
529
                                'amount' => 1,
530
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
531
                                'data' => [
532
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
533
                                    'who' => 'Jane',
534
                                ],
535
                                'cart' => '/v1/carts/8',
536
                                'product' => '/v1/products/10',
537
                                'cartItemDetailList' => [],
538
                            ],
539
                        ],
540
                        'order' => null,
541
                    ])
542
543
            ->then
544
                ->array($data = $this->testedInstance->serialize(
545
                    $cart,
546
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
547
                    ['serializeRelations' => ['cart_items']]
548
                ))
549
                    ->isIdenticalTo([
550
                        'weirdId' => '/v1/carts/8',
551
                        'status' => 'payed',
552
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
553
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
554
                        'cart_items' => [
555
                            [
556
                                'weirdId' => '/v1/cart_items/16',
557
                                'amount' => 1,
558
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
559
                                'data' => [
560
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
561
                                    'who' => 'Jane',
562
                                ],
563
                                'cart' => '/v1/carts/8',
564
                                'product' => '/v1/products/10',
565
                                'cartItemDetailList' => [],
566
                            ],
567
                        ],
568
                        'order' => null,
569
                    ])
570
571
            // reverse the serialization
572
            ->then
573
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
574
                ->string($cart->getId())
575
                    ->isEqualTo('/v1/carts/8')
576
                ->array($cart->getCartItemList())
577
                    ->size->isEqualTo(1)
578
                // ->object($cartItem = current($cart->getCartItemList()))
579
                //     ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
580
                // ->string($cartItem->getId())
581
                //     ->isEqualTo('/v1/cart_items/16')
582
            ;
583
    }
584
585
    public function testDeserializeWithExtraFields()
586
    {
587
        $this->createNewInstance();
588
589
        $this
590
            ->given($data = [
591
                '@foo' => 'bar',
592
                '@id' => '/v1/carts/8',
593
                'status' => 'payed',
594
                'clientPhoneNumber' => '+33 1 23 45 67 89',
595
                'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
596
                'cart_items' => [],
597
                'order' => null,
598
            ])
599
600
            ->then
601
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
602
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
603
        ;
604
    }
605
606
    public function testSerializingIriManyToOne()
607
    {
608
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
609
        $mapping = new Mapping();
610
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue46/'));
611
612
        $section = new Issue46\Section();
613
        $section->setId(46);
614
        $section->setIri('/sections/46');
615
        $section->setTitle('section title');
616
617
        $article = new Issue46\Article();
618
        $article->setSection($section);
619
620
        $this->createNewInstance($mapping);
621
622
        $this
623
            ->then
624
                ->array($this->testedInstance->serialize($article, 'Mapado\RestClientSdk\Tests\Model\Issue46\Article'))
625
                    ->isIdenticalTo([
626
                        'id' => null,
627
                        'section' => '/sections/46',
628
                    ])
629
630
                ->if($article->setIri('/articles/44'))
631
632
                ->array($this->testedInstance
633
                    ->serialize(
634
                        $section,
635
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section'
636
                    ))
637
                ->isIdenticalTo([
638
                    '@id' => '/sections/46',
639
                    'id' => 46,
640
                    'title' => 'section title',
641
                    'articleList' => [
642
                        '/articles/44',
643
                    ],
644
                ])
645
646
                ->array($this->testedInstance
647
                    ->serialize(
648
                        $section,
649
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section',
650
                        ['serializeRelations' => ['articleList']]
651
                    ))
652
                ->isIdenticalTo([
653
                    '@id' => '/sections/46',
654
                    'id' => 46,
655
                    'title' => 'section title',
656
                    'articleList' => [
657
                        [
658
                            '@id' => '/articles/44',
659
                            'id' => null,
660
                            'section' => '/sections/46',
661
                        ],
662
                    ],
663
                ])
664
        ;
665
    }
666
667
    public function testDeserializeEntityWithoutIriAttribute()
668
    {
669
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
670
        $mapping = new Mapping();
671
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
672
673
        $this->createNewInstance($mapping);
674
        $this
675
            ->given($data = [
676
                '@id' => '/v1/articles/8',
677
                'tag' => [
678
                    'name' => 'tag name',
679
                ],
680
            ])
681
682
            ->then
683
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
684
                    ->isInstanceOf(Issue75\Article::class)
685
                ->object($article->getTag())
686
                    ->isInstanceOf(Issue75\Tag::class)
687
688
            ->given($data = [
689
                '@id' => '/v1/articles/8',
690
                'tagList' => [
691
                    [
692
                        'name' => 'tag 1 name',
693
                    ],
694
                    [
695
                        'name' => 'tag 2 name',
696
                    ],
697
                ],
698
            ])
699
700
            ->then
701
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
702
                    ->isInstanceOf(Issue75\Article::class)
703
                ->array($tagList = $article->getTagList())
704
                    ->size->isEqualTo(2)
705
                ->object($tagList[0])
706
                    ->isInstanceOf(Issue75\Tag::class)
707
                ->string($tagList[0]->getName())
708
                    ->isIdenticalTo('tag 1 name')
709
                ->object($tagList[1])
710
                    ->isInstanceOf(Issue75\Tag::class)
711
                ->string($tagList[1]->getName())
712
                    ->isIdenticalTo('tag 2 name')
713
        ;
714
    }
715
716
    public function testSerializeEntityWithoutIriAttribute()
717
    {
718
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
719
        $mapping = new Mapping();
720
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
721
722
        $tag = new Issue75\Tag();
723
        $tag->setName('tag title');
724
725
        $article = new Issue75\Article();
726
        $article->setTitle('article title');
727
728
        $this->createNewInstance($mapping);
729
        $this
730
            ->then
731
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
732
                ->isIdenticalTo([
733
                    'title' => 'article title',
734
                    'tag' => null,
735
                    'tagList' => null,
736
                ])
737
738
            ->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...
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' => null,
746
                    ])
747
748
            ->if($article->setTagList([(new Issue75\Tag())->setName('tag 1')]))
749
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
750
                    ->isIdenticalTo([
751
                        'title' => 'article title',
752
                        'tag' => [
753
                            'name' => 'tag title',
754
                        ],
755
                        'tagList' => [
756
                            ['name' => 'tag 1'],
757
                        ],
758
                    ])
759
760
            ->then
761
                // as tags does not have an Attribute identifier, we ignore the serializeRelations context
762
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class, ['serializeRelations' => ['tag', 'tagList']]))
763
                    ->isIdenticalTo([
764
                        'title' => 'article title',
765
                        'tag' => [
766
                            'name' => 'tag title',
767
                        ],
768
                        'tagList' => [
769
                            ['name' => 'tag 1'],
770
                        ],
771
                    ])
772
        ;
773
    }
774
775
    public function testDeserializeEntityWithIntAsId()
776
    {
777
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
778
        $mapping = new Mapping();
779
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue90/'));
780
781
        $this->createNewInstance($mapping);
782
        $this
783
            ->given($data = [
784
                'id' => 8,
785
            ])
786
787
            ->then
788
                ->object($article = $this->testedInstance->deserialize($data, Issue90\WithIdInt::class))
789
                    ->isInstanceOf(Issue90\WithIdInt::class)
790
791
                ->object($this->unitOfWork->getDirtyEntity('8'))
792
        ;
793
    }
794
795
    public function testDeserializeEntityWithAnInexistantSetter()
796
    {
797
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
798
        $mapping = new Mapping();
799
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue80/'));
800
801
        $this->createNewInstance($mapping);
802
        $this
803
            ->given($data = [
804
                'id' => 8,
805
                'title' => 'some title',
806
            ])
807
            ->and($testedInstance = $this->testedInstance)
808
809
            ->then
810
                ->exception(function () use ($testedInstance, $data) {
0 ignored issues
show
Unused Code introduced by
The import $testedInstance is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
811
                    $article = $this->testedInstance->deserialize($data, Issue80\Article::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $article is dead and can be removed.
Loading history...
812
                })
813
                    ->isInstanceOf(MissingSetterException::class)
814
        ;
815
    }
816
817
    public function testDeserializeEntityWithPublicProperty()
818
    {
819
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
820
        $mapping = new Mapping();
821
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue89/'));
822
823
        $this->createNewInstance($mapping);
824
        $this
825
            ->given($data = [
826
                'id' => 8,
827
                'title' => 'some title',
828
                'tagList' => ['/tags/2'],
829
            ])
830
            ->and($testedInstance = $this->testedInstance)
831
832
            ->then
833
                ->object($article = $this->testedInstance->deserialize($data, Issue89\Article::class))
834
                    ->isInstanceOf(Issue89\Article::class)
835
836
                ->integer($article->id)
837
                    ->isIdenticalTo(8)
838
839
                ->string($article->title)
840
                    ->isEqualTo('some title')
841
        ;
842
    }
843
844
    /**
845
     * getMapping
846
     *
847
     * @return Mapping
848
     */
849
    private function getMapping($idKey = '@id')
850
    {
851
        $mapping = new Mapping('/v1');
852
        $mapping->setMapping([
853
            $this->getCartMetadata($idKey),
854
            $this->getCartItemMetadata($idKey),
855
            $this->getCartItemDetailMetadata($idKey),
856
            $this->getProductMetadata($idKey),
857
        ]);
858
859
        return $mapping;
860
    }
861
862
    /**
863
     * @param string $idKey
864
     */
865
    private function getProductMetadata($idKey)
866
    {
867
        $productMetadata = new ClassMetadata(
868
            'products',
869
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Product',
870
            ''
871
        );
872
873
        $productMetadata->setAttributeList([
874
            new Attribute($idKey, 'id', 'string', true),
875
            new Attribute('product_value', 'value'),
876
            new Attribute('currency'),
877
        ]);
878
879
        return $productMetadata;
880
    }
881
882
    /**
883
     * @param string $idKey
884
     */
885
    private function getCartItemDetailMetadata($idKey)
886
    {
887
        $cartItemDetailMetadata = new ClassMetadata(
888
            'cart_item_details',
889
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail',
890
            ''
891
        );
892
893
        $cartItemDetailMetadata->setRelationList([
894
            new Relation('cartItem', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
895
        ]);
896
        $cartItemDetailMetadata->setAttributeList([
897
            new Attribute($idKey, 'id', 'string', true),
898
            new Attribute('name'),
899
            new Attribute('cartItem'),
900
        ]);
901
902
        return $cartItemDetailMetadata;
903
    }
904
905
    /**
906
     * @param string $idKey
907
     */
908
    private function getCartItemMetadata($idKey)
909
    {
910
        $cartItemMetadata = new ClassMetadata(
911
            'cart_items',
912
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
913
            ''
914
        );
915
916
        $cartItemMetadata->setRelationList([
917
            new Relation('cart', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'),
918
            new Relation('product', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'),
919
            new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'),
920
        ]);
921
        $cartItemMetadata->setAttributeList([
922
            new Attribute($idKey, 'id', 'string', true),
923
            new Attribute('amount'),
924
            new Attribute('createdAt', 'createdAt', 'datetime'),
925
            new Attribute('data'),
926
            new Attribute('cart'),
927
            new Attribute('product'),
928
            new Attribute('cartItemDetailList'),
929
        ]);
930
931
        return $cartItemMetadata;
932
    }
933
934
    /**
935
     * @param string $idKey
936
     */
937
    private function getCartMetadata($idKey)
938
    {
939
        $cartMetadata = new ClassMetadata(
940
            'carts',
941
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
942
            ''
943
        );
944
        $cartMetadata->setAttributeList([
945
            new Attribute($idKey, 'id', 'string', true),
946
            new Attribute('status'),
947
            new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'),
948
            new Attribute('createdAt', 'createdAt', 'datetime'),
949
            new Attribute('cart_items', 'cartItemList'),
950
            new Attribute('order'),
951
        ]);
952
        $cartMetadata->setRelationList([
953
            new Relation('cart_items', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
954
            new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'),
955
        ]);
956
957
        return $cartMetadata;
958
    }
959
960
    /**
961
     * createNewCart
962
     *
963
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
964
     */
965
    private function createNewCart()
966
    {
967
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart();
968
        $cart->setStatus('payed');
969
        $cart->setCreatedAt(new DateTime('2015-09-20 12:08:00'));
970
971
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
972
        $clientPhoneNumber = $phoneNumberUtil->parse('+33123456789', PhoneNumberFormat::INTERNATIONAL);
973
        $cart->setClientPhoneNumber($clientPhoneNumber);
974
975
        return $cart;
976
    }
977
978
    /**
979
     * createCart
980
     *
981
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
982
     */
983
    private function createCart()
984
    {
985
        $cart = $this->createNewCart();
986
        $cart->setId('/v1/carts/8');
987
988
        return $cart;
989
    }
990
991
    /**
992
     * createKnownCartItem
993
     *
994
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
995
     */
996
    private function createKnownCartItem()
997
    {
998
        $cartItem = $this->createNewCartItem();
999
        $cartItem->setId('/v1/cart_items/16');
1000
        $cartItem->setAmount(1);
1001
        $cartItem->setCreatedAt(new DateTimeImmutable('2015-11-04 15:13:00'));
1002
        $cartItem->setData([
1003
            'when' => new DateTimeImmutable('2015-11-04 15:00:00'),
1004
            'who' => 'Jane',
1005
        ]);
1006
        $cartItem->setCart($this->createCart());
1007
1008
        return $cartItem;
1009
    }
1010
1011
    /**
1012
     * createNewCartItem
1013
     *
1014
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
1015
     */
1016
    private function createNewCartItem($addKnownedProduct = true)
1017
    {
1018
        $cartItem = new \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem();
1019
        $cartItem->setAmount(2);
1020
        $cartItem->setCreatedAt(new DateTimeImmutable('2015-09-20 12:11:00'));
1021
        $cartItem->setData([
1022
            'when' => new DateTime('2015-09-20 15:00:00'),
1023
            'who' => 'John',
1024
        ]);
1025
1026
        if ($addKnownedProduct) {
1027
            $cartItem->setProduct($this->createKnownedProduct());
1028
        }
1029
1030
        return $cartItem;
1031
    }
1032
1033
    /**
1034
     * createNewProduct
1035
     *
1036
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
1037
     */
1038
    private function createNewProduct()
1039
    {
1040
        $product = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product();
1041
1042
        $product->setValue(8.2);
1043
        $product->setCurrency('eur');
1044
1045
        return $product;
1046
    }
1047
1048
    /**
1049
     * createKnownedProduct
1050
     *
1051
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
1052
     */
1053
    private function createKnownedProduct()
1054
    {
1055
        $product = $this->createNewProduct();
1056
        $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

1056
        $product->setId(/** @scrutinizer ignore-type */ '/v1/products/10');
Loading history...
1057
1058
        return $product;
1059
    }
1060
1061
    private function createNewCartItemDetail()
1062
    {
1063
        $item = new \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail();
1064
1065
        $item->setName('Bill');
1066
1067
        return $item;
1068
    }
1069
1070
    /**
1071
     * createNewInstance
1072
     *
1073
     * @param Mapping $mapping
1074
     */
1075
    private function createNewInstance($mapping = null)
1076
    {
1077
        $mapping = $mapping ?: $this->getMapping();
1078
        $this->unitOfWork = new UnitOfWork($mapping);
1079
        $this->newTestedInstance($mapping, $this->unitOfWork);
1080
1081
        $this->mockGenerator->orphanize('__construct');
1082
        $this->mockGenerator->shuntParentClassCalls();
1083
        $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...
1084
        $this->mockGenerator->unshuntParentClassCalls();
1085
        $sdk = new \mock\Mapado\RestClientSdk\SdkClient($restClient, $mapping, $this->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...
1086
        $sdk->setFileCachePath(__DIR__ . '/../../cache/');
1087
1088
        $cartRepositoryMock = $this->getCartRepositoryMock($sdk, $restClient, $this->unitOfWork, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart');
1089
1090
        $this->calling($sdk)->getRepository = function ($modelName) use ($cartRepositoryMock) {
1091
            switch ($modelName) {
1092
                case 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart':
1093
                    return $cartRepositoryMock;
1094
                default:
1095
                    return;
1096
            }
1097
        };
1098
1099
        $this->testedInstance->setSdk($sdk);
1100
    }
1101
1102
    /**
1103
     * @param string $modelName
1104
     * @param UnitOfWork $unitOfWork
1105
     */
1106
    private function getCartRepositoryMock($sdk, $restClient, $unitOfWork, $modelName)
1107
    {
1108
        $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...
1109
            $sdk,
1110
            $restClient,
1111
            $unitOfWork,
1112
            $modelName
1113
        );
1114
1115
        $_this = $this;
1116
1117
        $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

1117
        $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...
1118
            return $_this->createCart();
1119
        };
1120
1121
        return $repository;
1122
    }
1123
}
1124