Passed
Push — master ( 0e744e...957281 )
by Julien
01:07 queued 11s
created

testDeserializeEntityWithAnInexistantSetter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 19
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 libphonenumber\PhoneNumberFormat;
10
use libphonenumber\PhoneNumberUtil;
11
use Mapado\RestClientSdk\Exception\MissingSetterException;
12
use Mapado\RestClientSdk\Mapping;
13
use Mapado\RestClientSdk\Mapping\Attribute;
14
use Mapado\RestClientSdk\Mapping\ClassMetadata;
15
use Mapado\RestClientSdk\Mapping\Driver\AnnotationDriver;
16
use Mapado\RestClientSdk\Mapping\Relation;
17
use Mapado\RestClientSdk\Tests\Model\Issue46;
18
use Mapado\RestClientSdk\Tests\Model\Issue75;
19
use Mapado\RestClientSdk\Tests\Model\Issue80;
20
use Mapado\RestClientSdk\Tests\Model\Issue89;
21
use Mapado\RestClientSdk\Tests\Model\Issue90;
22
use Mapado\RestClientSdk\Tests\Model\JsonLd;
23
use Mapado\RestClientSdk\UnitOfWork;
24
25
/**
26
 * Class Serializer
27
 *
28
 * @author Julien Deniau <[email protected]>
29
 */
30
class Serializer extends atoum
31
{
32
    /**
33
     * @var UnitOfWork
34
     */
35
    private $unitOfWork;
36
37
    /**
38
     * testJsonEncode
39
     */
40
    public function testJsonEncode()
41
    {
42
        $this->createNewInstance();
43
44
        $this
45
            ->given($cart = $this->createCart())
46
            ->then
47
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
48
                    ->isIdenticalTo([
49
                        '@id' => '/v1/carts/8',
50
                        'status' => 'payed',
51
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
52
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
53
                        'cart_items' => [],
54
                        'order' => null,
55
                    ])
56
57
            // reverse the serialization
58
            ->then
59
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
60
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
61
                ->string($cart->getId())
62
                    ->isEqualTo('/v1/carts/8')
63
                ->string($cart->getStatus())
64
                    ->isEqualTo('payed')
65
                ->datetime($cart->getCreatedAt())
66
                    ->isEqualTo(new \DateTime('2015-09-20T12:08:00'))
67
                ->array($cart->getCartItemList())
68
                    ->isEmpty()
69
70
        ;
71
    }
72
73
    /**
74
     * testJsonEncodeRelation
75
     */
76
    public function testJsonEncodeRelationWithLink()
77
    {
78
        $this->createNewInstance();
79
80
        $this
81
            ->given($cart = $this->createCart())
82
                ->and($cartItem = $this->createKnownCartItem())
83
                ->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...
84
85
            ->then
86
                ->array($data = $this->testedInstance->serialize(
87
                    $cart,
88
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
89
                    ['serializeRelations' => ['cart_items']]
90
                ))
91
                    ->isIdenticalTo([
92
                        '@id' => '/v1/carts/8',
93
                        'status' => 'payed',
94
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
95
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
96
                        'cart_items' => [
97
                            [
98
                                '@id' => '/v1/cart_items/16',
99
                                'amount' => 1,
100
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
101
                                'data' => [
102
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
103
                                    'who' => 'Jane',
104
                                ],
105
                                'cart' => '/v1/carts/8',
106
                                'product' => '/v1/products/10',
107
                                'cartItemDetailList' => [],
108
                            ],
109
                        ],
110
                        'order' => null,
111
                    ])
112
113
            ->then
114
                ->array($data = $this->testedInstance->serialize(
115
                    $cart,
116
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
117
                    ['serializeRelations' => ['cart_items']]
118
                ))
119
                    ->isIdenticalTo([
120
                        '@id' => '/v1/carts/8',
121
                        'status' => 'payed',
122
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
123
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
124
                        'cart_items' => [
125
                            [
126
                                '@id' => '/v1/cart_items/16',
127
                                'amount' => 1,
128
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
129
                                'data' => [
130
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
131
                                    'who' => 'Jane',
132
                                ],
133
                                'cart' => '/v1/carts/8',
134
                                'product' => '/v1/products/10',
135
                                'cartItemDetailList' => [],
136
                            ],
137
                        ],
138
                        'order' => null,
139
                    ])
140
141
            // reverse the serialization
142
            ->then
143
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
144
                ->array($cart->getCartItemList())
145
                    ->size->isEqualTo(1)
146
                ->object($cartItem = current($cart->getCartItemList()))
147
                    ->isInstanceOf(JsonLd\CartItem::class)
148
                ->string($cartItem->getId())
149
                    ->isEqualTo('/v1/cart_items/16')
150
            ;
151
    }
152
153
    /**
154
     * testJsonEncodeRelationWithoutLink
155
     */
156
    public function testJsonEncodeRelationWithoutLink()
157
    {
158
        $this->createNewInstance();
159
160
        $this
161
            ->given($cart = $this->createCart())
162
                ->and($cartItem = $this->createNewCartItem())
163
                ->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...
164
            ->then
165
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
166
                    ->isIdenticalTo([
167
                        '@id' => '/v1/carts/8',
168
                        'status' => 'payed',
169
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
170
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
171
                        'cart_items' => [
172
                            [
173
                                'amount' => 2,
174
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
175
                                'data' => [
176
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
177
                                    'who' => 'John',
178
                                ],
179
                                'product' => '/v1/products/10',
180
                                'cartItemDetailList' => [],
181
                            ],
182
                        ],
183
                        'order' => null,
184
                    ])
185
186
            // reverse the serialization
187
            ->then
188
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
189
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
190
                    ->size->isEqualTo(1)
191
                ->object($cartItemList[0])
192
                    ->isInstanceOf(JsonLd\CartItem::class)
193
                ->variable($cartItemList[0]->getId())
194
                    ->isNull
195
        ;
196
    }
197
198
    public function testSerializeThreeLevel()
199
    {
200
        $this->createNewInstance();
201
202
        $this
203
            ->given($cart = $this->createNewCart())
204
                ->and($cartItem = $this->createNewCartItem())
205
                ->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...
206
            ->then
207
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
208
                    ->isIdenticalTo([
209
                        'status' => 'payed',
210
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
211
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
212
                        'cart_items' => [
213
                            [
214
                                'amount' => 2,
215
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
216
                                'data' => [
217
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
218
                                    'who' => 'John',
219
                                ],
220
                                'product' => '/v1/products/10',
221
                                'cartItemDetailList' => [],
222
                            ],
223
                        ],
224
                        'order' => null,
225
                    ])
226
        ;
227
    }
228
229
    /**
230
     * testJsonEncodeRelationWithoutLinkMultipleLevel
231
     */
232
    public function testJsonEncodeRelationWithoutLinkMultipleLevel()
233
    {
234
        $this->createNewInstance();
235
        $this
236
            ->given($cart = $this->createCart())
237
                ->and($cartItem = $this->createNewCartItem(false))
238
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
239
                ->and($cartItem->addCartItemDetailList($this->createNewCartItemDetail()))
240
            ->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...
241
            ->then
242
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
243
                    ->isIdenticalTo([
244
                        '@id' => '/v1/carts/8',
245
                        'status' => 'payed',
246
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
247
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
248
                        'cart_items' => [
249
                            [
250
                                'amount' => 2,
251
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
252
                                'data' => [
253
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
254
                                    'who' => 'John',
255
                                ],
256
                                'cartItemDetailList' => [
257
                                    ['name' => 'Bill'],
258
                                    ['name' => 'Bill'],
259
                                ],
260
                            ],
261
                        ],
262
                        'order' => null,
263
                    ])
264
        ;
265
    }
266
267
    /**
268
     * testJsonEncodeMixRelations
269
     */
270
    public function testJsonEncodeMixRelations()
271
    {
272
        $this->createNewInstance();
273
274
        $this
275
            ->given($cart = $this->createCart())
276
                ->and($cartItem = $this->createNewCartItem())
277
                ->and($knownedCartItem = $this->createKnownCartItem())
278
            ->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...
279
                ->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...
280
            ->then
281
                ->array($data = $this->testedInstance->serialize(
282
                    $cart,
283
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
284
                    ['serializeRelations' => ['cart_items']]
285
                ))
286
                    ->isIdenticalTo([
287
                        '@id' => '/v1/carts/8',
288
                        'status' => 'payed',
289
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
290
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
291
                        'cart_items' => [
292
                            [
293
                                '@id' => '/v1/cart_items/16',
294
                                'amount' => 1,
295
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
296
                                'data' => [
297
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
298
                                    'who' => 'Jane',
299
                                ],
300
                                'cart' => '/v1/carts/8',
301
                                'product' => '/v1/products/10',
302
                                'cartItemDetailList' => [],
303
                            ],
304
                            [
305
                                'amount' => 2,
306
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
307
                                'data' => [
308
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
309
                                    'who' => 'John',
310
                                ],
311
                                'product' => '/v1/products/10',
312
                                'cartItemDetailList' => [],
313
                            ],
314
                        ],
315
                        'order' => null,
316
                    ])
317
318
            // reverse the serialization
319
            ->then
320
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
321
                ->array($cartItemList = $cart->getCartItemList()) // we can not uneserialize an unlinked entity
322
                    ->size->isEqualTo(2)
323
                ->object($cartItem = $cartItemList[0])
324
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
325
                ->string($cartItem->getId())
326
                    ->isEqualTo('/v1/cart_items/16')
327
                ->object($cartItem = $cartItemList[1])
328
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
329
                ->variable($cartItem->getId())
330
                    ->isNull()
331
        ;
332
    }
333
334
    /**
335
     * testNotAllowedSerialization
336
     */
337
    public function testNotAllowedSerialization()
338
    {
339
        $this->createNewInstance();
340
        $this
341
            ->given($cartItem = $this->createNewCartItem())
342
                ->and($cartItemDetail = $this->createNewCartItemDetail())
343
                ->and($cartItemDetail->setCartItem($cartItem))
344
                ->and($testedInstance = $this->testedInstance)
345
            ->then
346
                ->object($cartItemDetail->getCartItem())
347
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
348
                ->exception(function () use ($testedInstance, $cartItemDetail) {
349
                    $testedInstance->serialize($cartItemDetail, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail');
350
                })
351
                    ->isInstanceOf('Mapado\RestClientSdk\Exception\SdkException')
352
        ;
353
    }
354
355
    /**
356
     * testMultipleLevelSerialization
357
     */
358
    public function testMultipleLevelSerialization()
359
    {
360
        $this->createNewInstance();
361
        $this
362
            ->given($cart = $this->createNewCart())
363
                ->and($cartItem = $this->createNewCartItem())
364
                ->and($cartItem->setCart($cart))
365
            ->then
366
                ->array($this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
367
                    ->isIdenticalTo([
368
                        'status' => 'payed',
369
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
370
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
371
                        'cart_items' => [
372
                            [
373
                                'amount' => 2,
374
                                'createdAt' => (new \DateTime('2015-09-20T12:11:00'))->format(DateTime::RFC3339),
375
                                'data' => [
376
                                    'when' => (new \DateTime('2015-09-20T15:00:00'))->format(DateTime::RFC3339),
377
                                    'who' => 'John',
378
                                ],
379
                                'product' => '/v1/products/10',
380
                                'cartItemDetailList' => [],
381
                            ],
382
                        ],
383
                        'order' => null,
384
                    ])
385
386
        ;
387
    }
388
389
    /**
390
     * testLinkedUnserialize
391
     */
392
    public function testLinkedUnserialize()
393
    {
394
        $this->createNewInstance();
395
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
396
397
        $this
398
            ->given($data = [
399
                    '@id' => '/v1/carts/8',
400
                    'status' => 'payed',
401
                    'clientPhoneNumber' => $phoneNumberUtil->parse('+330123456789', PhoneNumberFormat::INTERNATIONAL),
402
                    'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
403
                    'cart_items' => [
404
                        [
405
                            '@id' => '/v1/cart_items/16',
406
                            'amount' => 2,
407
                            'createdAt' => (new \DateTime('2015-09-20T12:11:00+00:00'))->format(DateTime::RFC3339),
408
                            'data' => [
409
                                'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
410
                                'who' => 'John',
411
                            ],
412
                            'product' => '/v1/products/10',
413
                            'cartItemDetailList' => [],
414
                        ],
415
                    ],
416
                ])
417
            ->then
418
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
419
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
420
                ->object($cart->getClientPhoneNumber())
421
                    ->isInstanceOf('libphonenumber\PhoneNumber')
422
                ->array($cart->getCartItemList())
423
                    ->size->isEqualTo(1)
424
                ->object($cartItem = current($cart->getCartItemList()))
425
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
426
                ->string($cartItem->getId())
427
                    ->isEqualTo('/v1/cart_items/16')
428
                ->integer($cartItem->getAmount())
429
                    ->isEqualTo(2)
430
                ->datetime($cartItem->getCreatedAt())
431
                    ->isEqualTo(new \DateTime('2015-09-20T12:11:00+00:00'))
432
                ->array($cartItem->getData())
433
                    ->isEqualTo([
434
                        'when' => (new \DateTime('2015-09-20T15:00:00+00:00'))->format(DateTime::RFC3339),
435
                        'who' => 'John',
436
                    ])
437
                ->object($cartItem->getProduct())
438
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Product')
439
                ->string($cartItem->getProduct()->getId())
440
                    ->isEqualTo('/v1/products/10')
441
                ->array($cartItem->getCartItemDetailList())
442
                    ->isEmpty()
443
        ;
444
445
        $this->createNewInstance();
446
        $this
447
            ->given($data = [
448
                    '@id' => '/v1/cart_items/16',
449
                    'amount' => 2,
450
                    'cart' => [
451
                        '@id' => '/v1/carts/10',
452
                        'status' => 'waiting',
453
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
454
                    ],
455
                ])
456
457
            ->then
458
                ->object($cartItem = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'))
459
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
460
                ->object($cart = $cartItem->getCart())
461
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
462
                ->string($cart->getClientPhoneNumber())
463
                    ->isEqualTo('+33 1 23 45 67 89')
464
                ->string($cart->getId())
465
                    ->isEqualTo('/v1/carts/10')
466
                ->string($cart->getStatus())
467
                    ->isEqualTo('waiting')
468
        ;
469
    }
470
471
    public function testSerializeNullValues()
472
    {
473
        $this->createNewInstance();
474
        $this
475
            ->given($cart = $this->createNewCart())
476
                ->and($cart->setStatus(null))
477
                ->and($cart->setOrder(null))
478
            ->then
479
                ->array($data = $this->testedInstance->serialize($cart, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
480
                    ->isIdenticalTo([
481
                        'status' => null,
482
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
483
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
484
                        'cart_items' => [],
485
                        'order' => null,
486
                    ])
487
        ;
488
    }
489
490
    public function testSerializingAttributeNameDiffThanPropertyName()
491
    {
492
        $this->createNewInstance();
493
        $this
494
            ->given($product = $this->createNewProduct())
495
            ->then
496
                ->array($data = $this->testedInstance->serialize($product, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'))
497
                ->isIdenticalTo([
498
                    'product_value' => 8.2,
499
                    'currency' => 'eur',
500
                ])
501
        ;
502
    }
503
504
    public function testWeirdIdentifier()
505
    {
506
        $mapping = $this->getMapping('weirdId');
507
        $this->createNewInstance($mapping);
508
509
        $this
510
            ->given($cart = $this->createCart())
511
                ->and($cartItem = $this->createKnownCartItem())
512
                ->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...
513
514
            ->then
515
                ->array($data = $this->testedInstance->serialize(
516
                    $cart,
517
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
518
                    ['serializeRelations' => ['cart_items']]
519
                ))
520
                    ->isIdenticalTo([
521
                        'weirdId' => '/v1/carts/8',
522
                        'status' => 'payed',
523
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
524
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
525
                        'cart_items' => [
526
                            [
527
                                'weirdId' => '/v1/cart_items/16',
528
                                'amount' => 1,
529
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
530
                                'data' => [
531
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
532
                                    'who' => 'Jane',
533
                                ],
534
                                'cart' => '/v1/carts/8',
535
                                'product' => '/v1/products/10',
536
                                'cartItemDetailList' => [],
537
                            ],
538
                        ],
539
                        'order' => null,
540
                    ])
541
542
            ->then
543
                ->array($data = $this->testedInstance->serialize(
544
                    $cart,
545
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
546
                    ['serializeRelations' => ['cart_items']]
547
                ))
548
                    ->isIdenticalTo([
549
                        'weirdId' => '/v1/carts/8',
550
                        'status' => 'payed',
551
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
552
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
553
                        'cart_items' => [
554
                            [
555
                                'weirdId' => '/v1/cart_items/16',
556
                                'amount' => 1,
557
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
558
                                'data' => [
559
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
560
                                    'who' => 'Jane',
561
                                ],
562
                                'cart' => '/v1/carts/8',
563
                                'product' => '/v1/products/10',
564
                                'cartItemDetailList' => [],
565
                            ],
566
                        ],
567
                        'order' => null,
568
                    ])
569
570
            // reverse the serialization
571
            ->then
572
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
573
                ->string($cart->getId())
574
                    ->isEqualTo('/v1/carts/8')
575
                ->array($cart->getCartItemList())
576
                    ->size->isEqualTo(1)
577
                // ->object($cartItem = current($cart->getCartItemList()))
578
                //     ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
579
                // ->string($cartItem->getId())
580
                //     ->isEqualTo('/v1/cart_items/16')
581
            ;
582
    }
583
584
    public function testDeserializeWithExtraFields()
585
    {
586
        $this->createNewInstance();
587
588
        $this
589
            ->given($data = [
590
                '@foo' => 'bar',
591
                '@id' => '/v1/carts/8',
592
                'status' => 'payed',
593
                'clientPhoneNumber' => '+33 1 23 45 67 89',
594
                'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
595
                'cart_items' => [],
596
                'order' => null,
597
            ])
598
599
            ->then
600
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
601
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')
602
        ;
603
    }
604
605
    public function testSerializingIriManyToOne()
606
    {
607
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
608
        $mapping = new Mapping();
609
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue46/'));
610
611
        $section = new Issue46\Section();
612
        $section->setId(46);
613
        $section->setIri('/sections/46');
614
        $section->setTitle('section title');
615
616
        $article = new Issue46\Article();
617
        $article->setSection($section);
618
619
        $this->createNewInstance($mapping);
620
621
        $this
622
            ->then
623
                ->array($this->testedInstance->serialize($article, 'Mapado\RestClientSdk\Tests\Model\Issue46\Article'))
624
                    ->isIdenticalTo([
625
                        'id' => null,
626
                        'section' => '/sections/46',
627
                    ])
628
629
                ->if($article->setIri('/articles/44'))
630
631
                ->array($this->testedInstance
632
                    ->serialize(
633
                        $section,
634
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section'
635
                    ))
636
                ->isIdenticalTo([
637
                    '@id' => '/sections/46',
638
                    'id' => 46,
639
                    'title' => 'section title',
640
                    'articleList' => [
641
                        '/articles/44',
642
                    ],
643
                ])
644
645
                ->array($this->testedInstance
646
                    ->serialize(
647
                        $section,
648
                        'Mapado\RestClientSdk\Tests\Model\Issue46\Section',
649
                        ['serializeRelations' => ['articleList']]
650
                    ))
651
                ->isIdenticalTo([
652
                    '@id' => '/sections/46',
653
                    'id' => 46,
654
                    'title' => 'section title',
655
                    'articleList' => [
656
                        [
657
                            '@id' => '/articles/44',
658
                            'id' => null,
659
                            'section' => '/sections/46',
660
                        ],
661
                    ],
662
                ])
663
        ;
664
    }
665
666
    public function testDeserializeEntityWithoutIriAttribute()
667
    {
668
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
669
        $mapping = new Mapping();
670
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
671
672
        $this->createNewInstance($mapping);
673
        $this
674
            ->given($data = [
675
                '@id' => '/v1/articles/8',
676
                'tag' => [
677
                    'name' => 'tag name',
678
                ],
679
            ])
680
681
            ->then
682
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
683
                    ->isInstanceOf(Issue75\Article::class)
684
                ->object($article->getTag())
685
                    ->isInstanceOf(Issue75\Tag::class)
686
687
            ->given($data = [
688
                '@id' => '/v1/articles/8',
689
                'tagList' => [
690
                    [
691
                        'name' => 'tag 1 name',
692
                    ],
693
                    [
694
                        'name' => 'tag 2 name',
695
                    ],
696
                ],
697
            ])
698
699
            ->then
700
                ->object($article = $this->testedInstance->deserialize($data, Issue75\Article::class))
701
                    ->isInstanceOf(Issue75\Article::class)
702
                ->array($tagList = $article->getTagList())
703
                    ->size->isEqualTo(2)
704
                ->object($tagList[0])
705
                    ->isInstanceOf(Issue75\Tag::class)
706
                ->string($tagList[0]->getName())
707
                    ->isIdenticalTo('tag 1 name')
708
                ->object($tagList[1])
709
                    ->isInstanceOf(Issue75\Tag::class)
710
                ->string($tagList[1]->getName())
711
                    ->isIdenticalTo('tag 2 name')
712
        ;
713
    }
714
715
    public function testSerializeEntityWithoutIriAttribute()
716
    {
717
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
718
        $mapping = new Mapping();
719
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue75/'));
720
721
        $tag = new Issue75\Tag();
722
        $tag->setName('tag title');
723
724
        $article = new Issue75\Article();
725
        $article->setTitle('article title');
726
727
        $this->createNewInstance($mapping);
728
        $this
729
            ->then
730
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
731
                ->isIdenticalTo([
732
                    'title' => 'article title',
733
                    'tag' => null,
734
                    'tagList' => null,
735
                ])
736
737
            ->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...
738
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
739
                    ->isIdenticalTo([
740
                        'title' => 'article title',
741
                        'tag' => [
742
                            'name' => 'tag title',
743
                        ],
744
                        'tagList' => null,
745
                    ])
746
747
            ->if($article->setTagList([(new Issue75\Tag())->setName('tag 1')]))
748
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class))
749
                    ->isIdenticalTo([
750
                        'title' => 'article title',
751
                        'tag' => [
752
                            'name' => 'tag title',
753
                        ],
754
                        'tagList' => [
755
                            ['name' => 'tag 1'],
756
                        ],
757
                    ])
758
759
            ->then
760
                // as tags does not have an Attribute identifier, we ignore the serializeRelations context
761
                ->array($data = $this->testedInstance->serialize($article, Issue75\Article::class, ['serializeRelations' => ['tag', 'tagList']]))
762
                    ->isIdenticalTo([
763
                        'title' => 'article title',
764
                        'tag' => [
765
                            'name' => 'tag title',
766
                        ],
767
                        'tagList' => [
768
                            ['name' => 'tag 1'],
769
                        ],
770
                    ])
771
        ;
772
    }
773
774
    public function testDeserializeEntityWithIntAsId()
775
    {
776
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
777
        $mapping = new Mapping();
778
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue90/'));
779
780
        $this->createNewInstance($mapping);
781
        $this
782
            ->given($data = [
783
                'id' => 8,
784
            ])
785
786
            ->then
787
                ->object($article = $this->testedInstance->deserialize($data, Issue90\WithIdInt::class))
788
                    ->isInstanceOf(Issue90\WithIdInt::class)
789
790
                ->object($this->unitOfWork->getDirtyEntity('8'))
791
        ;
792
    }
793
794
    public function testDeserializeEntityWithAnInexistantSetter()
795
    {
796
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
797
        $mapping = new Mapping();
798
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue80/'));
799
800
        $this->createNewInstance($mapping);
801
        $this
802
            ->given($data = [
803
                'id' => 8,
804
                'title' => 'some title',
805
            ])
806
            ->and($testedInstance = $this->testedInstance)
807
808
            ->then
809
                ->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...
810
                    $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...
811
                })
812
                    ->isInstanceOf(MissingSetterException::class)
813
        ;
814
    }
815
816
    public function testDeserializeEntityWithPublicProperty()
817
    {
818
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../../cache/');
819
        $mapping = new Mapping();
820
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../../Model/Issue89/'));
821
822
        $this->createNewInstance($mapping);
823
        $this
824
            ->given($data = [
825
                'id' => 8,
826
                'title' => 'some title',
827
                'tagList' => ['/tags/2'],
828
            ])
829
            ->and($testedInstance = $this->testedInstance)
830
831
            ->then
832
                ->object($article = $this->testedInstance->deserialize($data, Issue89\Article::class))
833
                    ->isInstanceOf(Issue89\Article::class)
834
835
                ->integer($article->id)
836
                    ->isIdenticalTo(8)
837
838
                ->string($article->title)
839
                    ->isEqualTo('some title')
840
        ;
841
    }
842
843
    /**
844
     * getMapping
845
     *
846
     * @return Mapping
847
     */
848
    private function getMapping($idKey = '@id')
849
    {
850
        $mapping = new Mapping('/v1');
851
        $mapping->setMapping([
852
            $this->getCartMetadata($idKey),
853
            $this->getCartItemMetadata($idKey),
854
            $this->getCartItemDetailMetadata($idKey),
855
            $this->getProductMetadata($idKey),
856
        ]);
857
858
        return $mapping;
859
    }
860
861
    /**
862
     * @param string $idKey
863
     */
864
    private function getProductMetadata($idKey)
865
    {
866
        $productMetadata = new ClassMetadata(
867
            'products',
868
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Product',
869
            ''
870
        );
871
872
        $productMetadata->setAttributeList([
873
            new Attribute($idKey, 'id', 'string', true),
874
            new Attribute('product_value', 'value'),
875
            new Attribute('currency'),
876
        ]);
877
878
        return $productMetadata;
879
    }
880
881
    /**
882
     * @param string $idKey
883
     */
884
    private function getCartItemDetailMetadata($idKey)
885
    {
886
        $cartItemDetailMetadata = new ClassMetadata(
887
            'cart_item_details',
888
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail',
889
            ''
890
        );
891
892
        $cartItemDetailMetadata->setRelationList([
893
            new Relation('cartItem', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
894
        ]);
895
        $cartItemDetailMetadata->setAttributeList([
896
            new Attribute($idKey, 'id', 'string', true),
897
            new Attribute('name'),
898
            new Attribute('cartItem'),
899
        ]);
900
901
        return $cartItemDetailMetadata;
902
    }
903
904
    /**
905
     * @param string $idKey
906
     */
907
    private function getCartItemMetadata($idKey)
908
    {
909
        $cartItemMetadata = new ClassMetadata(
910
            'cart_items',
911
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
912
            ''
913
        );
914
915
        $cartItemMetadata->setRelationList([
916
            new Relation('cart', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'),
917
            new Relation('product', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'),
918
            new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'),
919
        ]);
920
        $cartItemMetadata->setAttributeList([
921
            new Attribute($idKey, 'id', 'string', true),
922
            new Attribute('amount'),
923
            new Attribute('createdAt', 'createdAt', 'datetime'),
924
            new Attribute('data'),
925
            new Attribute('cart'),
926
            new Attribute('product'),
927
            new Attribute('cartItemDetailList'),
928
        ]);
929
930
        return $cartItemMetadata;
931
    }
932
933
    /**
934
     * @param string $idKey
935
     */
936
    private function getCartMetadata($idKey)
937
    {
938
        $cartMetadata = new ClassMetadata(
939
            'carts',
940
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
941
            ''
942
        );
943
        $cartMetadata->setAttributeList([
944
            new Attribute($idKey, 'id', 'string', true),
945
            new Attribute('status'),
946
            new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'),
947
            new Attribute('createdAt', 'createdAt', 'datetime'),
948
            new Attribute('cart_items', 'cartItemList'),
949
            new Attribute('order'),
950
        ]);
951
        $cartMetadata->setRelationList([
952
            new Relation('cart_items', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
953
            new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'),
954
        ]);
955
956
        return $cartMetadata;
957
    }
958
959
    /**
960
     * createNewCart
961
     *
962
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
963
     */
964
    private function createNewCart()
965
    {
966
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart();
967
        $cart->setStatus('payed');
968
        $cart->setCreatedAt(new DateTime('2015-09-20 12:08:00'));
969
970
        $phoneNumberUtil = PhoneNumberUtil::getInstance();
971
        $clientPhoneNumber = $phoneNumberUtil->parse('+33123456789', PhoneNumberFormat::INTERNATIONAL);
972
        $cart->setClientPhoneNumber($clientPhoneNumber);
973
974
        return $cart;
975
    }
976
977
    /**
978
     * createCart
979
     *
980
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart
981
     */
982
    private function createCart()
983
    {
984
        $cart = $this->createNewCart();
985
        $cart->setId('/v1/carts/8');
986
987
        return $cart;
988
    }
989
990
    /**
991
     * createKnownCartItem
992
     *
993
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
994
     */
995
    private function createKnownCartItem()
996
    {
997
        $cartItem = $this->createNewCartItem();
998
        $cartItem->setId('/v1/cart_items/16');
999
        $cartItem->setAmount(1);
1000
        $cartItem->setCreatedAt(new DateTime('2015-11-04 15:13:00'));
1001
        $cartItem->setData([
1002
            'when' => new DateTime('2015-11-04 15:00:00'),
1003
            'who' => 'Jane',
1004
        ]);
1005
        $cartItem->setCart($this->createCart());
1006
1007
        return $cartItem;
1008
    }
1009
1010
    /**
1011
     * createNewCartItem
1012
     *
1013
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem
1014
     */
1015
    private function createNewCartItem($addKnownedProduct = true)
1016
    {
1017
        $cartItem = new \Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem();
1018
        $cartItem->setAmount(2);
1019
        $cartItem->setCreatedAt(new DateTime('2015-09-20 12:11:00'));
1020
        $cartItem->setData([
1021
            'when' => new DateTime('2015-09-20 15:00:00'),
1022
            'who' => 'John',
1023
        ]);
1024
1025
        if ($addKnownedProduct) {
1026
            $cartItem->setProduct($this->createKnownedProduct());
1027
        }
1028
1029
        return $cartItem;
1030
    }
1031
1032
    /**
1033
     * createNewProduct
1034
     *
1035
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
1036
     */
1037
    private function createNewProduct()
1038
    {
1039
        $product = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product();
1040
1041
        $product->setValue(8.2);
1042
        $product->setCurrency('eur');
1043
1044
        return $product;
1045
    }
1046
1047
    /**
1048
     * createKnownedProduct
1049
     *
1050
     * @return \Mapado\RestClientSdk\Tests\Model\JsonLd\Product
1051
     */
1052
    private function createKnownedProduct()
1053
    {
1054
        $product = $this->createNewProduct();
1055
        $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

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

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