Code Duplication    Length = 85-86 lines in 2 locations

test/Serializer/JsonApiSerializerTest.php 2 locations

@@ 561-646 (lines=86) @@
558
        $this->assertSame($expectedJson, $scope->toJson());
559
    }
560
561
    public function testSerializingCollectionResourceWithHasOneInclude()
562
    {
563
        $this->manager->parseIncludes('author');
564
565
        $booksData = [
566
            [
567
                'id' => 1,
568
                'title' => 'Foo',
569
                'year' => '1991',
570
                '_author' => [
571
                    'id' => 1,
572
                    'name' => 'Dave',
573
                ],
574
            ],
575
            [
576
                'id' => 2,
577
                'title' => 'Bar',
578
                'year' => '1997',
579
                '_author' => [
580
                    'id' => 2,
581
                    'name' => 'Bob',
582
                ],
583
            ],
584
        ];
585
586
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
587
        $scope = new Scope($this->manager, $resource);
588
589
        $expected = [
590
            'data' => [
591
                [
592
                    'type' => 'books',
593
                    'id' => '1',
594
                    'attributes' => [
595
                        'title' => 'Foo',
596
                        'year' => 1991,
597
                    ],
598
                    'relationships' => [
599
                        'author' => [
600
                            'data' => [
601
                                'type' => 'people',
602
                                'id' => '1',
603
                            ],
604
                        ],
605
                    ],
606
                ],
607
                [
608
                    'type' => 'books',
609
                    'id' => '2',
610
                    'attributes' => [
611
                        'title' => 'Bar',
612
                        'year' => 1997,
613
                    ],
614
                    'relationships' => [
615
                        'author' => [
616
                            'data' => [
617
                                'type' => 'people',
618
                                'id' => '2',
619
                            ],
620
                        ],
621
                    ],
622
                ],
623
            ],
624
            'included' => [
625
                [
626
                    'type' => 'people',
627
                    'id' => '1',
628
                    'attributes' => [
629
                        'name' => 'Dave',
630
                    ],
631
                ],
632
                [
633
                    'type' => 'people',
634
                    'id' => '2',
635
                    'attributes' => [
636
                        'name' => 'Bob',
637
                    ],
638
                ],
639
            ],
640
        ];
641
642
        $this->assertSame($expected, $scope->toArray());
643
644
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"relationships":{"author":{"data":{"type":"people","id":"2"}}}}],"included":[{"type":"people","id":"1","attributes":{"name":"Dave"}},{"type":"people","id":"2","attributes":{"name":"Bob"}}]}';
645
        $this->assertSame($expectedJson, $scope->toJson());
646
    }
647
648
    public function testSerializingCollectionResourceWithEmptyHasOneInclude()
649
    {
@@ 1063-1147 (lines=85) @@
1060
        $this->assertSame($expectedJson, $scope->toJson());
1061
    }
1062
1063
    public function testSerializingItemResourceWithNestedIncludes()
1064
    {
1065
        $this->manager->parseIncludes(['author', 'author.published']);
1066
1067
        $bookData = [
1068
            'id' => 1,
1069
            'title' => 'Foo',
1070
            'year' => '1991',
1071
            '_author' => [
1072
                'id' => 1,
1073
                'name' => 'Dave',
1074
                '_published' => [
1075
                    [
1076
                        'id' => 1,
1077
                        'title' => 'Foo',
1078
                        'year' => '1991',
1079
                    ],
1080
                    [
1081
                        'id' => 2,
1082
                        'title' => 'Bar',
1083
                        'year' => '2015',
1084
                    ],
1085
                ],
1086
            ],
1087
        ];
1088
1089
        $resource = new Item($bookData, new JsonApiBookTransformer(), 'books');
1090
1091
        $scope = new Scope($this->manager, $resource);
1092
1093
        $expected = [
1094
            'data' => [
1095
                'type' => 'books',
1096
                'id' => '1',
1097
                'attributes' => [
1098
                    'title' => 'Foo',
1099
                    'year' => 1991,
1100
                ],
1101
                'relationships' => [
1102
                    'author' => [
1103
                        'data' => [
1104
                            'type' => 'people',
1105
                            'id' => '1',
1106
                        ],
1107
                    ],
1108
                ],
1109
            ],
1110
            'included' => [
1111
                [
1112
                    'type' => 'books',
1113
                    'id' => '2',
1114
                    'attributes' => [
1115
                        'title' => 'Bar',
1116
                        'year' => 2015,
1117
                    ],
1118
                ],
1119
                [
1120
                    'type' => 'people',
1121
                    'id' => '1',
1122
                    'attributes' => [
1123
                        'name' => 'Dave',
1124
                    ],
1125
                    'relationships' => [
1126
                        'published' => [
1127
                            'data' => [
1128
                                [
1129
                                    'type' => 'books',
1130
                                    'id' => '1',
1131
                                ],
1132
                                [
1133
                                    'type' => 'books',
1134
                                    'id' => '2',
1135
                                ],
1136
                            ],
1137
                        ],
1138
                    ],
1139
                ],
1140
            ],
1141
        ];
1142
1143
        $this->assertSame($expected, $scope->toArray());
1144
1145
        $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},"included":[{"type":"books","id":"2","attributes":{"title":"Bar","year":2015}},{"type":"people","id":"1","attributes":{"name":"Dave"},"relationships":{"published":{"data":[{"type":"books","id":"1"},{"type":"books","id":"2"}]}}}]}';
1146
        $this->assertSame($expectedJson, $scope->toJson());
1147
    }
1148
1149
    public function testSerializingItemResourceWithSelfLink()
1150
    {