Code Duplication    Length = 52-55 lines in 3 locations

test/JsonApiSerializerTest.php 3 locations

@@ 199-253 (lines=55) @@
196
        $this->assertSame($expectedJson, $scope->toJson());
197
    }
198
199
    public function testSerializingItemResourceWithHasOneDasherizedInclude() : void
200
    {
201
        $this->manager->parseIncludes('co-author');
202
203
        $bookData = [
204
            'id' => 1,
205
            'title' => 'Foo',
206
            'year' => '1991',
207
            '_author' => [
208
                'id' => 1,
209
                'name' => 'Dave',
210
            ],
211
            '_co_author' => [
212
                'id' => 2,
213
                'name' => 'Jim',
214
            ],
215
        ];
216
217
        $resource = new Item($bookData, new JsonApiBookTransformer(), 'books');
218
219
        $scope = new Scope($this->manager, $resource);
220
221
        $expected = [
222
            'data' => [
223
                'type' => 'books',
224
                'id' => '1',
225
                'attributes' => [
226
                    'title' => 'Foo',
227
                    'year' => 1991,
228
                ],
229
                'relationships' => [
230
                    'co-author' => [
231
                        'data' => [
232
                            'type' => 'people',
233
                            'id' => '2',
234
                        ],
235
                    ],
236
                ],
237
            ],
238
            'included' => [
239
                [
240
                    'type' => 'people',
241
                    'id' => '2',
242
                    'attributes' => [
243
                        'name' => 'Jim',
244
                    ],
245
                ],
246
            ],
247
        ];
248
249
        $this->assertSame($expected, $scope->toArray());
250
251
        $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"co-author":{"data":{"type":"people","id":"2"}}}},"included":[{"type":"people","id":"2","attributes":{"name":"Jim"}}]}';
252
        $this->assertSame($expectedJson, $scope->toJson());
253
    }
254
255
    public function testSerializingItemResourceWithEmptyHasOneInclude() : void
256
    {
@@ 513-564 (lines=52) @@
510
        $this->assertSame($expectedJson, $scope->toJson());
511
    }
512
513
    public function testSerializingCollectionResourceWithoutIncludes() : void
514
    {
515
        $booksData = [
516
            [
517
                'id' => 1,
518
                'title' => 'Foo',
519
                'year' => '1991',
520
                '_author' => [
521
                    'id' => 1,
522
                    'name' => 'Dave',
523
                ],
524
            ],
525
            [
526
                'id' => 2,
527
                'title' => 'Bar',
528
                'year' => '1997',
529
                '_author' => [
530
                    'id' => 2,
531
                    'name' => 'Bob',
532
                ],
533
            ],
534
        ];
535
536
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
537
        $scope = new Scope($this->manager, $resource);
538
539
        $expected = [
540
            'data' => [
541
                [
542
                    'type' => 'books',
543
                    'id' => '1',
544
                    'attributes' => [
545
                        'title' => 'Foo',
546
                        'year' => 1991,
547
                    ],
548
                ],
549
                [
550
                    'type' => 'books',
551
                    'id' => '2',
552
                    'attributes' => [
553
                        'title' => 'Bar',
554
                        'year' => 1997,
555
                    ],
556
                ],
557
            ],
558
        ];
559
560
        $this->assertSame($expected, $scope->toArray());
561
562
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}]}';
563
        $this->assertSame($expectedJson, $scope->toJson());
564
    }
565
566
    public function testSerializingCollectionResourceWithHasOneInclude() : void
567
    {
@@ 932-986 (lines=55) @@
929
        $this->assertSame($expectedJson, $scope->toJson());
930
    }
931
932
    public function testSerializingCollectionResourceWithMeta() : void
933
    {
934
        $booksData = [
935
            [
936
                'id' => 1,
937
                'title' => 'Foo',
938
                'year' => '1991',
939
                '_author' => [
940
                    'name' => 'Dave',
941
                ],
942
            ],
943
            [
944
                'id' => 2,
945
                'title' => 'Bar',
946
                'year' => '1997',
947
                '_author' => [
948
                    'name' => 'Bob',
949
                ],
950
            ],
951
        ];
952
953
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
954
        $resource->setMetaValue('foo', 'bar');
955
956
        $scope = new Scope($this->manager, $resource);
957
958
        $expected = [
959
            'data' => [
960
                [
961
                    'type' => 'books',
962
                    'id' => '1',
963
                    'attributes' => [
964
                        'title' => 'Foo',
965
                        'year' => 1991,
966
                    ],
967
                ],
968
                [
969
                    'type' => 'books',
970
                    'id' => '2',
971
                    'attributes' => [
972
                        'title' => 'Bar',
973
                        'year' => 1997,
974
                    ],
975
                ],
976
            ],
977
            'meta' => [
978
                'foo' => 'bar',
979
            ],
980
        ];
981
982
        $this->assertSame($expected, $scope->toArray());
983
984
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}],"meta":{"foo":"bar"}}';
985
        $this->assertSame($expectedJson, $scope->toJson());
986
    }
987
988
    public function testSerializingCollectionResourceWithDuplicatedIncludeData() : void
989
    {