Code Duplication    Length = 52-55 lines in 3 locations

test/JsonApiSerializerTest.php 3 locations

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