Code Duplication    Length = 76-79 lines in 2 locations

Tests/Units/Model/Serializer.php 2 locations

@@ 68-143 (lines=76) @@
65
     * @access public
66
     * @return void
67
     */
68
    public function testJsonEncodeRelationWithLink()
69
    {
70
        $this->createNewInstance();
71
72
        $this
73
            ->given($cart = $this->createCart())
74
                ->and($cartItem = $this->createKnownCartItem())
75
                ->and($cart->addCartItemList($cartItem))
76
77
            ->then
78
                ->array($data = $this->testedInstance->serialize(
79
                    $cart,
80
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
81
                    [ 'serializeRelations' => ['cart_items'] ]
82
                ))
83
                    ->isIdenticalTo([
84
                        '@id' => '/v1/carts/8',
85
                        'status' => 'payed',
86
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
87
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
88
                        'cart_items' => [
89
                            [
90
                                '@id' => '/v1/cart_items/16',
91
                                'amount' => 1,
92
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
93
                                'data' => [
94
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
95
                                    'who' => 'Jane',
96
                                ],
97
                                'cart' => '/v1/carts/8',
98
                                'product' => '/v1/products/10',
99
                                'cartItemDetailList' => [],
100
                            ],
101
                        ],
102
                        'order' => null,
103
                    ])
104
105
            ->then
106
                ->array($data = $this->testedInstance->serialize(
107
                    $cart,
108
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
109
                    [ 'serializeRelations' => ['cart_items'] ]
110
                ))
111
                    ->isIdenticalTo([
112
                        '@id' => '/v1/carts/8',
113
                        'status' => 'payed',
114
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
115
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
116
                        'cart_items' => [
117
                            [
118
                                '@id' => '/v1/cart_items/16',
119
                                'amount' => 1,
120
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
121
                                'data' => [
122
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
123
                                    'who' => 'Jane',
124
                                ],
125
                                'cart' => '/v1/carts/8',
126
                                'product' => '/v1/products/10',
127
                                'cartItemDetailList' => [],
128
                            ],
129
                        ],
130
                        'order' => null,
131
                    ])
132
133
            // reverse the serialization
134
            ->then
135
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
136
                ->array($cart->getCartItemList())
137
                    ->size->isEqualTo(1)
138
                ->object($cartItem = current($cart->getCartItemList()))
139
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
140
                ->string($cartItem->getId())
141
                    ->isEqualTo('/v1/cart_items/16')
142
            ;
143
    }
144
145
    /**
146
     * testJsonEncodeRelationWithoutLink
@@ 506-584 (lines=79) @@
503
        ;
504
    }
505
506
    public function testWeirdIdentifier()
507
    {
508
        $mapping = $this->getMapping('weirdId');
509
        $this->createNewInstance($mapping);
510
511
        $this
512
            ->given($cart = $this->createCart())
513
                ->and($cartItem = $this->createKnownCartItem())
514
                ->and($cart->addCartItemList($cartItem))
515
516
            ->then
517
                ->array($data = $this->testedInstance->serialize(
518
                    $cart,
519
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
520
                    [ 'serializeRelations' => ['cart_items'] ]
521
                ))
522
                    ->isIdenticalTo([
523
                        'weirdId' => '/v1/carts/8',
524
                        'status' => 'payed',
525
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
526
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
527
                        'cart_items' => [
528
                            [
529
                                'weirdId' => '/v1/cart_items/16',
530
                                'amount' => 1,
531
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
532
                                'data' => [
533
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
534
                                    'who' => 'Jane',
535
                                ],
536
                                'cart' => '/v1/carts/8',
537
                                'product' => '/v1/products/10',
538
                                'cartItemDetailList' => [],
539
                            ],
540
                        ],
541
                        'order' => null,
542
                    ])
543
544
            ->then
545
                ->array($data = $this->testedInstance->serialize(
546
                    $cart,
547
                    'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
548
                    [ 'serializeRelations' => ['cart_items'] ]
549
                ))
550
                    ->isIdenticalTo([
551
                        'weirdId' => '/v1/carts/8',
552
                        'status' => 'payed',
553
                        'clientPhoneNumber' => '+33 1 23 45 67 89',
554
                        'createdAt' => (new \DateTime('2015-09-20T12:08:00'))->format(DateTime::RFC3339),
555
                        'cart_items' => [
556
                            [
557
                                'weirdId' => '/v1/cart_items/16',
558
                                'amount' => 1,
559
                                'createdAt' => (new \DateTime('2015-11-04 15:13:00'))->format(DateTime::RFC3339),
560
                                'data' => [
561
                                    'when' => (new \DateTime('2015-11-04 15:00:00'))->format(DateTime::RFC3339),
562
                                    'who' => 'Jane',
563
                                ],
564
                                'cart' => '/v1/carts/8',
565
                                'product' => '/v1/products/10',
566
                                'cartItemDetailList' => [],
567
                            ],
568
                        ],
569
                        'order' => null,
570
                    ])
571
572
            // reverse the serialization
573
            ->then
574
                ->object($cart = $this->testedInstance->deserialize($data, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart'))
575
                ->string($cart->getId())
576
                    ->isEqualTo('/v1/carts/8')
577
                ->array($cart->getCartItemList())
578
                    ->size->isEqualTo(1)
579
                // ->object($cartItem = current($cart->getCartItemList()))
580
                //     ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')
581
                // ->string($cartItem->getId())
582
                //     ->isEqualTo('/v1/cart_items/16')
583
            ;
584
    }
585
586
    public function testDeserializeWithExtraFields()
587
    {