Code Duplication    Length = 85-86 lines in 2 locations

test/JsonApiSerializerTest.php 2 locations

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