Code Duplication    Length = 85-86 lines in 2 locations

test/JsonApiSerializerTest.php 2 locations

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