Passed
Push — master ( b035d4...5b9eb2 )
by Julien
02:44
created

UnitOfWork::testWithMoreData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace Mapado\RestClientSdk\Tests\Units;
4
5
use atoum;
6
use Mapado\RestClientSdk\Mapping as RestMapping;
7
use Mapado\RestClientSdk\Mapping\Attribute;
8
use Mapado\RestClientSdk\Mapping\ClassMetadata;
9
use Mapado\RestClientSdk\Mapping\Relation;
10
11
/**
12
 * UnitOfWork
13
 *
14
 * @uses atoum
15
 * @author Julien Petit <[email protected]>
16
 */
17
class UnitOfWork extends atoum
18
{
19
    private $unitOfWork;
0 ignored issues
show
Unused Code introduced by
The property $unitOfWork is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
21
    public function testRegister()
22
    {
23
        $mapping = $this->getMapping();
24
        $unitOfWork = $this->newTestedInstance($mapping);
25
26
        $ticket = (object) [
27
            'firstname' => 'foo',
28
            'lastname' => 'bar',
29
            'email' => '[email protected]',
30
        ];
31
        $unitOfWork->registerClean('@id1', $ticket);
32
        $this
33
            ->then
34
                ->variable($unitOfWork->getDirtyEntity('@id1'))
35
                    ->isEqualTo($ticket)
36
        ;
37
    }
38
39
    public function testSimpleEntity()
40
    {
41
        $mapping = $this->getMapping();
42
        $unitOfWork = $this->newTestedInstance($mapping);
43
44
        $this
45
            ->array($unitOfWork->getDirtyData(
46
                [
47
                    '@id' => '/v12/carts/1',
48
                ],
49
                [
50
                    '@id' => '/v12/carts/1',
51
                ],
52
                $this->getCartMetadata()
53
            ))
54
            ->isEqualTo([])
55
            ->then
56
            ->array($unitOfWork->getDirtyData(
57
                [
58
                    '@id' => '/v12/carts/1',
59
                    'status' => 'payed',
60
                    'order' => '/v12/orders/1',
61
                ],
62
                [
63
                    '@id' => '/v12/carts/1',
64
                    'status' => 'payed',
65
                    'order' => '/v12/orders/1',
66
                ],
67
                $this->getCartMetadata()
68
            ))
69
            ->isEqualTo([])
70
            ->then
71
            ->array($unitOfWork->getDirtyData(
72
                [
73
                    '@id' => '/v12/carts/1',
74
                    'status' => 'payed',
75
                ],
76
                [
77
                    '@id' => '/v12/carts/1',
78
                    'status' => 'waiting',
79
                ],
80
                $this->getCartMetadata()
81
            ))
82
            ->isEqualTo(['status' => 'payed'])
83
            ->then
84
            ->array($unitOfWork->getDirtyData(
85
                [
86
                    '@id' => '/v12/carts/2',
87
                    'status' => 'payed',
88
                ],
89
                [
90
                    '@id' => '/v12/carts/1',
91
                    'status' => 'waiting',
92
                ],
93
                $this->getCartMetadata()
94
            ))
95
            ->isEqualTo([
96
                '@id' => '/v12/carts/2',
97
                'status' => 'payed',
98
            ])
99
            ->then
100
            ->array($unitOfWork->getDirtyData(
101
                [
102
                    '@id' => '/v12/carts/1',
103
                    'status' => 'payed',
104
                    'someData' => [
105
                        'foo' => 'bar',
106
                        'loo' => 'baz',
107
                    ],
108
                ],
109
                [
110
                    '@id' => '/v12/carts/1',
111
                    'status' => 'payed',
112
                    'someData' => [
113
                        'foo' => 'bar',
114
                    ],
115
                ],
116
                $this->getCartMetadata()
117
            ))
118
            ->isEqualTo([
119
                'someData' => [
120
                    'foo' => 'bar',
121
                    'loo' => 'baz',
122
                ],
123
            ])
124
            ->then
125
            ->array($unitOfWork->getDirtyData(
126
                [
127
                    '@id' => '/v12/carts/1',
128
                    'status' => 'payed',
129
                    'someData' => [
130
                        'foo' => 'bar',
131
                        'bad' => 'baz',
132
                    ],
133
                ],
134
                [
135
                    '@id' => '/v12/carts/1',
136
                    'status' => 'payed',
137
                    'someData' => [
138
                        'foo' => 'bar',
139
                        'bad' => 'baz',
140
                    ],
141
                ],
142
                $this->getCartMetadata()
143
            ))
144
            ->isEqualTo([])
145
        ;
146
    }
147
148
    public function testWithMoreData()
149
    {
150
        $mapping = $this->getMapping();
151
        $unitOfWork = $this->newTestedInstance($mapping);
152
153
        $this
154
            ->array($unitOfWork->getDirtyData(
155
                [
156
                    '@id' => '/v12/carts/1',
157
                ],
158
                [
159
                    '@id' => '/v12/carts/1',
160
                    'foo' => 'bar',
161
                    'status' => 'ok',
162
                ],
163
                $this->getCartMetadata()
164
            ))
165
            ->isEqualTo([])
166
        ;
167
    }
168
169
    public function testManyToOneRelation()
170
    {
171
        $mapping = $this->getMapping();
172
        $unitOfWork = $this->newTestedInstance($mapping);
173
174
        $this
175
            ->array($unitOfWork->getDirtyData(
176
                [
177
                    '@id' => '/v12/carts/1',
178
                    'order' => '/v1/orders/2',
179
                ],
180
                [
181
                    '@id' => '/v12/carts/1',
182
                    'order' => [ '@id' => '/v1/orders/1' ],
183
                ],
184
                $this->getCartMetadata()
185
            ))
186
            ->isEqualTo([
187
                'order' => '/v1/orders/2',
188
            ])
189
190
            ->then
191
            ->array($unitOfWork->getDirtyData(
192
                [
193
                    '@id' => '/v12/carts/1',
194
                    'order' => [
195
                        '@id' => '/v1/orders/2',
196
                    ]
197
                ],
198
                [
199
                    '@id' => '/v12/carts/1',
200
                    'order' => '/v1/orders/1',
201
                ],
202
                $this->getCartMetadata()
203
            ))
204
            ->isEqualTo([
205
                'order' => [
206
                    '@id' => '/v1/orders/2',
207
                ],
208
            ])
209
210
            ->then
211
            ->array($unitOfWork->getDirtyData(
212
                [
213
                    '@id' => '/v12/carts/1',
214
                    'order' => [
215
                        '@id' => '/v1/orders/2',
216
                        'status' => 'payed',
217
                    ]
218
                ],
219
                [
220
                    '@id' => '/v12/carts/1',
221
                    'order' => [
222
                        '@id' => '/v1/orders/1',
223
                        'status' => 'payed',
224
                    ],
225
                ],
226
                $this->getCartMetadata()
227
            ))
228
            ->isEqualTo([
229
                'order' => [
230
                    '@id' => '/v1/orders/2',
231
                ],
232
            ])
233
234
            ->then
235
            ->array($unitOfWork->getDirtyData(
236
                [
237
                    '@id' => '/v12/carts/1',
238
                    'order' => [
239
                        '@id' => '/v1/orders/2',
240
                        'status' => 'payed',
241
                    ]
242
                ],
243
                [
244
                    '@id' => '/v12/carts/1',
245
                    'order' => [
246
                        '@id' => '/v1/orders/1',
247
                        'status' => 'waiting',
248
                    ],
249
                ],
250
                $this->getCartMetadata()
251
            ))
252
            ->isEqualTo([
253
                'order' => [
254
                    '@id' => '/v1/orders/2',
255
                    'status' => 'payed',
256
                ],
257
            ])
258
        ;
259
    }
260
261 View Code Duplication
    public function testNoChanges()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
    {
263
        $mapping = $this->getMapping();
264
        $unitOfWork = $this->newTestedInstance($mapping);
265
266
        $this
267
            ->given($newSerializedModel = [
268
                '@id' => '/v12/carts/1',
269
                'cartItemList' => [
270
                    '/v12/cart_items/1',
271
                    '/v12/cart_items/2',
272
                    '/v12/cart_items/3',
273
                ],
274
            ])
275
            ->then
276
                ->variable($unitOfWork->getDirtyData(
277
                    $newSerializedModel,
278
                    [
279
                        '@id' => '/v12/carts/1',
280
                        'cartItemList' => [
281
                            '/v12/cart_items/1',
282
                            '/v12/cart_items/2',
283
                            '/v12/cart_items/3',
284
                        ],
285
                    ],
286
                    $this->getCartMetadata()
287
                ))
288
                ->isEqualTo(
289
                    [
290
                    ]
291
                )
292
            ->then
293
                ->variable($unitOfWork->getDirtyData(
294
                    [
295
                        '@id' => '/v12/carts/1',
296
                        'cartItemList' => [
297
                            [
298
                                '@id' => '/v12/cart_items/1',
299
                                'amount' => 1,
300
                            ],
301
                            [
302
                                '@id' => '/v12/cart_items/2',
303
                                'amount' => 1,
304
                            ],
305
                        ],
306
                    ],
307
                    [
308
                        '@id' => '/v12/carts/1',
309
                        'cartItemList' => [
310
                            [
311
                                '@id' => '/v12/cart_items/1',
312
                                'amount' => 1,
313
                            ],
314
                            [
315
                                '@id' => '/v12/cart_items/2',
316
                                'amount' => 1,
317
                            ],
318
                        ],
319
                    ],
320
                    $this->getCartMetadata()
321
                ))
322
                ->isEqualTo(
323
                    [
324
                    ]
325
                )
326
        ;
327
    }
328
329 View Code Duplication
    public function testNoMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
330
    {
331
        $mapping = $this->getMapping();
332
        $unitOfWork = $this->newTestedInstance($mapping);
333
334
        $this
335
            ->given($newSerializedModel = [
336
                '@id' => '/v12/carts/1',
337
                'cartInfo' => [
338
                    [
339
                        'firstname' => 'john',
340
                        'lastname' => 'doe',
341
                    ],
342
                ],
343
            ])
344
            ->then
345
                ->variable($unitOfWork->getDirtyData(
346
                    $newSerializedModel,
347
                    [
348
                        '@id' => '/v12/carts/1',
349
                        'cartInfo' => [
350
                            [
351
                                'firstname' => 'john',
352
                                'lastname' => 'doe',
353
                            ],
354
                        ],
355
                    ],
356
                    $this->getCartMetadata()
357
                ))
358
                ->isEqualTo(
359
                    [
360
                    ]
361
                )
362
            ->then
363
                ->variable($unitOfWork->getDirtyData(
364
                    [
365
                        '@id' => '/v12/carts/1',
366
                        'cartItemList' => [
367
                            [
368
                                '@id' => '/v12/cart_items/1',
369
                                'amount' => 1,
370
                            ],
371
                            [
372
                                '@id' => '/v12/cart_items/2',
373
                                'amount' => 1,
374
                            ],
375
                        ],
376
                    ],
377
                    [
378
                        '@id' => '/v12/carts/1',
379
                        'cartItemList' => [
380
                            [
381
                                '@id' => '/v12/cart_items/1',
382
                                'amount' => 1,
383
                            ],
384
                            [
385
                                '@id' => '/v12/cart_items/2',
386
                                'amount' => 1,
387
                            ],
388
                        ],
389
                    ],
390
                    $this->getCartMetadata()
391
                ))
392
                ->isEqualTo(
393
                    [
394
                    ]
395
                )
396
        ;
397
    }
398
399
    public function testRemoveItem()
400
    {
401
        $mapping = $this->getMapping();
402
        $unitOfWork = $this->newTestedInstance($mapping);
403
404
        $this
405
            ->then
406
                ->variable($unitOfWork->getDirtyData(
407
                    [
408
                        '@id' => '/v12/carts/1',
409
                        'cartItemList' => [
410
                            '/v12/cart_items/1',
411
                            '/v12/cart_items/2',
412
                        ],
413
                    ],
414
                    [
415
                        '@id' => '/v12/carts/1',
416
                        'cartItemList' => [
417
                            '/v12/cart_items/1',
418
                            '/v12/cart_items/2',
419
                            '/v12/cart_items/3',
420
                        ],
421
                    ],
422
                    $this->getCartMetadata()
423
                ))
424
                ->isEqualTo(
425
                    [
426
                        'cartItemList' => [
427
                            '/v12/cart_items/1',
428
                            '/v12/cart_items/2',
429
                        ],
430
                    ]
431
                )
432
            ->then
433
                ->variable($unitOfWork->getDirtyData(
434
                    [
435
                        '@id' => '/v12/carts/1',
436
                        'cartItemList' => [
437
                            '/v12/cart_items/1',
438
                            '/v12/cart_items/3',
439
                        ],
440
                    ],
441
                    [
442
                        '@id' => '/v12/carts/1',
443
                        'cartItemList' => [
444
                            '/v12/cart_items/1',
445
                            '/v12/cart_items/2',
446
                            '/v12/cart_items/3',
447
                        ],
448
                    ],
449
                    $this->getCartMetadata()
450
                ))
451
                ->isEqualTo(
452
                    [
453
                        'cartItemList' => [
454
                            '/v12/cart_items/1',
455
                            '/v12/cart_items/3',
456
                        ],
457
                    ]
458
                )
459
            ->then
460
                ->variable($unitOfWork->getDirtyData(
461
                    [
462
                        '@id' => '/v12/carts/1',
463
                        'cartItemList' => [
464
                            [
465
                                '@id' => '/v12/cart_items/1',
466
                                'amount' => 2,
467
                            ],
468
                        ],
469
                    ],
470
                    [
471
                        '@id' => '/v12/carts/1',
472
                        'cartItemList' => [
473
                            [
474
                                '@id' => '/v12/cart_items/1',
475
                                'amount' => 2,
476
                            ],
477
                            [
478
                                '@id' => '/v12/cart_items/2',
479
                                'amount' => 1,
480
                            ],
481
                        ],
482
                    ],
483
                    $this->getCartMetadata()
484
                ))
485
                ->isEqualTo(
486
                    [
487
                        'cartItemList' => [
488
                            [
489
                                '@id' => '/v12/cart_items/1',
490
                            ],
491
                        ],
492
                    ]
493
                )
494
            ->then
495
                ->variable($unitOfWork->getDirtyData(
496
                    [
497
                        '@id' => '/v12/carts/1',
498
                        'cartItemList' => [
499
                            [
500
                                '@id' => '/v12/cart_items/2',
501
                                'amount' => 1,
502
                            ],
503
                        ],
504
                    ],
505
                    [
506
                        '@id' => '/v12/carts/1',
507
                        'cartItemList' => [
508
                            [
509
                                '@id' => '/v12/cart_items/1',
510
                                'amount' => 2,
511
                            ],
512
                            [
513
                                '@id' => '/v12/cart_items/2',
514
                                'amount' => 1,
515
                            ],
516
                        ],
517
                    ],
518
                    $this->getCartMetadata()
519
                ))
520
                ->isEqualTo(
521
                    [
522
                        'cartItemList' => [
523
                            [
524
                                '@id' => '/v12/cart_items/2',
525
                            ],
526
                        ],
527
                    ]
528
                )
529
            ->then
530
                ->array($unitOfWork->getDirtyData(
531
                    [
532
                        '@id' => '/v12/carts/1',
533
                        'cartItemList' => [
534
                            [
535
                                '@id' => '/v12/cart_items/2',
536
                                'amount' => 2,
537
                            ],
538
                        ],
539
                    ],
540
                    [
541
                        '@id' => '/v12/carts/1',
542
                        'cartItemList' => [
543
                            [
544
                                '@id' => '/v12/cart_items/1',
545
                                'amount' => 2,
546
                            ],
547
                            [
548
                                '@id' => '/v12/cart_items/2',
549
                                'amount' => 1,
550
                            ],
551
                        ],
552
                    ],
553
                    $this->getCartMetadata()
554
                ))
555
                ->isEqualTo(
556
                    [
557
                        'cartItemList' => [
558
                            [
559
                                '@id' => '/v12/cart_items/2',
560
                                'amount' => 2,
561
                            ],
562
                        ],
563
                    ]
564
                )
565
        ;
566
    }
567
568
    public function testAddItem()
569
    {
570
        $mapping = $this->getMapping();
571
        $unitOfWork = $this->newTestedInstance($mapping);
572
573
        $this
574
            ->then
575
                ->variable($unitOfWork->getDirtyData(
576
                    [
577
                        '@id' => '/v12/carts/1',
578
                        'cartItemList' => [
579
                            '/v12/cart_items/1',
580
                            '/v12/cart_items/2',
581
                            '/v12/cart_items/3',
582
                        ],
583
                    ],
584
                    [
585
                        '@id' => '/v12/carts/1',
586
                        'cartItemList' => [
587
                            '/v12/cart_items/1',
588
                            '/v12/cart_items/2',
589
                        ],
590
                    ],
591
                    $this->getCartMetadata()
592
                ))
593
                ->isEqualTo(
594
                    [
595
                        'cartItemList' => [
596
                            '/v12/cart_items/1',
597
                            '/v12/cart_items/2',
598
                            '/v12/cart_items/3',
599
                        ],
600
                    ]
601
                )
602
            ->then
603
                ->variable($unitOfWork->getDirtyData(
604
                    [
605
                        '@id' => '/v12/carts/1',
606
                        'cartItemList' => [
607
                            [
608
                                '@id' => '/v12/cart_items/1',
609
                                'amount' => 1,
610
                            ],
611
                            [
612
                                '@id' => '/v12/cart_items/2',
613
                                'amount' => 1,
614
                            ],
615
                        ],
616
                    ],
617
                    [
618
                        '@id' => '/v12/carts/1',
619
                        'cartItemList' => [
620
                            [
621
                                '@id' => '/v12/cart_items/1',
622
                                'amount' => 1,
623
                            ],
624
                        ],
625
                    ],
626
                    $this->getCartMetadata()
627
                ))
628
                ->isEqualTo(
629
                    [
630
                        'cartItemList' => [
631
                            [
632
                                '@id' => '/v12/cart_items/1',
633
                            ],
634
                            [
635
                                '@id' => '/v12/cart_items/2',
636
                                'amount' => 1,
637
                            ],
638
                        ],
639
                    ]
640
                )
641
        ;
642
    }
643
644
    public function testSendOnlyDirty()
645
    {
646
        $mapping = $this->getMapping();
647
        $unitOfWork = $this->newTestedInstance($mapping);
648
649
        $this
650
            ->then
651
                ->variable($unitOfWork->getDirtyData(
652
                    [
653
                        '@id' => '/v12/carts/1',
654
                        'cartItemList' => [
655
                            [
656
                                '@id' => '/v12/cart_items/1',
657
                                'amount' => 2,
658
                            ],
659
                            [
660
                                '@id' => '/v12/cart_items/2',
661
                                'amount' => 1,
662
                            ],
663
                        ],
664
                    ],
665
                    [
666
                        '@id' => '/v12/carts/1',
667
                        'cartItemList' => [
668
                            [
669
                                '@id' => '/v12/cart_items/1',
670
                                'amount' => 1,
671
                            ],
672
                            [
673
                                '@id' => '/v12/cart_items/2',
674
                                'amount' => 1,
675
                            ],
676
                        ],
677
                    ],
678
                    $this->getCartMetadata()
679
                ))
680
                ->isEqualTo(
681
                    [
682
                        'cartItemList' => [
683
                            [
684
                                '@id' => '/v12/cart_items/1',
685
                                'amount' => 2,
686
                            ],
687
                        ],
688
                    ]
689
                )
690
             ->then
691
                ->variable($unitOfWork->getDirtyData(
692
                    [
693
                        '@id' => '/v12/carts/1',
694
                        'status' => 'ok',
695
                        'clientPhoneNumber' => '+33123456789',
696
                    ],
697
                    [
698
                        '@id' => '/v12/carts/1',
699
                        'status' => 'ko',
700
                        'clientPhoneNumber' => '+33123456789',
701
                    ],
702
                    $this->getCartMetadata()
703
                ))
704
                ->isEqualTo(
705
                    [
706
                        'status' => 'ok',
707
                    ]
708
                )
709
            ->then
710
                ->variable($unitOfWork->getDirtyData(
711
                    [
712
                        'cartItemList' => [
713
                            [
714
                                '@id' => '/v12/cart_items/1',
715
                                'amount' => 1,
716
                                'cartItemDetailList' => [
717
                                    [
718
                                        '@id' => '/v12/cart_item_details/1',
719
                                        'name' => '',
720
                                    ],
721
                                ],
722
                            ],
723
                            [
724
                                '@id' => '/v12/cart_items/2',
725
                                'amount' => 1,
726
                            ],
727
                            [
728
                                '@id' => '/v12/cart_items/3',
729
                                'amount' => 1,
730
                                'cartItemDetailList' => [
731
                                    [
732
                                        '@id' => '/v12/cart_item_details/2',
733
                                        'name' => '',
734
                                    ],
735
                                ],
736
                            ],
737
                        ],
738
                    ],
739
                    [
740
                        'cartItemList' => [
741
                            [
742
                                '@id' => '/v12/cart_items/1',
743
                                'amount' => 2,
744
                                'cartItemDetailList' => [
745
                                    '@id' => '/v12/cart_item_details/1',
746
                                    'name' => 'foo',
747
                                ],
748
                            ],
749
                            [
750
                                '@id' => '/v12/cart_items/3',
751
                                'amount' => 1,
752
                            ],
753
                        ],
754
                    ],
755
                    $this->getCartMetadata()
756
                ))
757
                ->isEqualTo(
758
                    [
759
                        'cartItemList' => [
760
                            [
761
                                'amount' => 1,
762
                                'cartItemDetailList' => [
763
                                    [
764
                                        '@id' => '/v12/cart_item_details/1',
765
                                        'name' => '',
766
                                    ],
767
                                ],
768
                                '@id' => '/v12/cart_items/1',
769
                            ],
770
                            [
771
                                '@id' => '/v12/cart_items/2',
772
                                'amount' => 1,
773
                            ],
774
                            [
775
                                '@id' => '/v12/cart_items/3',
776
                                'cartItemDetailList' => [
777
                                    [
778
                                        '@id' => '/v12/cart_item_details/2',
779
                                        'name' => '',
780
                                    ]
781
                                ],
782
                            ],
783
                        ]
784
                    ]
785
                )
786
        ;
787
    }
788
789
    public function testNoMetadataChangeArray()
790
    {
791
        $mapping = $this->getMapping();
792
        $unitOfWork = $this->newTestedInstance($mapping);
793
794
        $this
795
            ->given($newSerializedModel = [
796
                '@id' => '/v12/carts/1',
797
                'cartInfo' => [
798
                    [
799
                        'firstname' => 'jane',
800
                        'lastname' => 'doe',
801
                        'children' => ['rusty', 'john-john-junior'],
802
                    ],
803
                ],
804
            ])
805
            ->then
806
            ->variable($unitOfWork->getDirtyData(
807
                $newSerializedModel,
808
                [
809
                    '@id' => '/v12/carts/1',
810
                    'cartInfo' => [
811
                        [
812
                            'firstname' => 'john',
813
                            'lastname' => 'doe',
814
                            'children' => ['rusty', 'john-john-junior'],
815
                        ],
816
                    ],
817
                ],
818
                $this->getCartMetadata()
819
            ))
820
            ->isEqualTo(
821
                [
822
                    'cartInfo' => [
823
                        [
824
                            'firstname' => 'jane',
825
                            'lastname' => 'doe',
826
                            'children' => ['rusty', 'john-john-junior'],
827
                        ],
828
                    ],
829
                ]
830
            )
831
832
            ->then
833
            ->variable($unitOfWork->getDirtyData(
834
                [
835
                    '@id' => '/v12/carts/1',
836
                    'order' => [
837
                        '@id' => '/v12/orders/1',
838
                        'customerPaidAmount' => 1500,
839
                        'status' => 'awaiting_payment',
840
                    ],
841
                ],
842
                [
843
                    '@id' => '/v12/carts/1',
844
                    'order' => [
845
                        '@id' => '/v12/orders/1',
846
                        'customerPaidAmount' => 1000,
847
                        'status' => 'awaiting_payment',
848
                    ],
849
                ],
850
                $this->getCartMetadata()
851
            ))
852
            ->isEqualTo(
853
                [
854
                    'order' => [
855
                        '@id' => '/v12/orders/1',
856
                        'customerPaidAmount' => 1500,
857
                    ],
858
                ]
859
            )
860
861
        ;
862
    }
863
864
    private function getMapping()
865
    {
866
        $mapping = $mapping = new RestMapping();
867
        $mapping->setMapping([
868
            $this->getOrderMetadata(),
869
            $this->getCartMetadata(),
870
            $this->getCartItemMetadata(),
871
            $this->getCartItemDetailMetadata(),
872
        ]);
873
874
        return $mapping;
875
    }
876
877 View Code Duplication
    private function getOrderMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
878
    {
879
        $orderMetadata = new ClassMetadata(
880
            'orders',
881
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
882
            ''
883
        );
884
885
        $orderMetadata->setAttributeList([
886
            new Attribute('@id', 'id', 'string', true),
887
            new Attribute('customerPaidAmount', 'customerPaidAmount', 'int'),
888
            new Attribute('status'),
889
        ]);
890
891
        $orderMetadata->setRelationList([
892
        ]);
893
894
        return $orderMetadata;
895
    }
896
897 View Code Duplication
    private function getCartMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
898
    {
899
        $cartMetadata = new ClassMetadata(
900
            'carts',
901
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
902
            ''
903
        );
904
905
        $cartMetadata->setAttributeList([
906
            new Attribute('@id', 'id', 'string', true),
907
            new Attribute('status'),
908
            new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'),
909
            new Attribute('createdAt', 'createdAt', 'datetime'),
910
            new Attribute('cart_items', 'cartItemList'),
911
            new Attribute('order'),
912
        ]);
913
914
        $cartMetadata->setRelationList([
915
            new Relation('cartItemList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
916
            new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'),
917
        ]);
918
919
        return $cartMetadata;
920
    }
921
922 View Code Duplication
    private function getCartItemMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
923
    {
924
        $cartItemMetadata = new ClassMetadata(
925
            'cart_items',
926
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
927
            ''
928
        );
929
930
        $cartItemMetadata->setAttributeList([
931
            new Attribute('@id', 'id', 'string', true),
932
            new Attribute('amount'),
933
            new Attribute('cartItemDetailList'),
934
        ]);
935
936
        $cartItemMetadata->setRelationList([
937
            new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'),
938
        ]);
939
940
        return $cartItemMetadata;
941
    }
942
943 View Code Duplication
    private function getCartItemDetailMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
944
    {
945
        $cartItemDetailMetadata = new ClassMetadata(
946
            'cart_item_details',
947
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail',
948
            ''
949
        );
950
951
        $cartItemDetailMetadata->setAttributeList([
952
            new Attribute('@id', 'id', 'string', true),
953
            new Attribute('name'),
954
        ]);
955
956
        return $cartItemDetailMetadata;
957
    }
958
}
959