Code Duplication    Length = 61-63 lines in 2 locations

test/Serializer/JsonApiSerializerTest.php 2 locations

@@ 1024-1084 (lines=61) @@
1021
        $this->assertSame($expectedJson, $scope->toJson());
1022
    }
1023
1024
    public function testSerializingCollectionResourceWithSelfLink()
1025
    {
1026
        $baseUrl = 'http://example.com';
1027
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1028
1029
        $booksData = [
1030
            [
1031
                'id' => 1,
1032
                'title' => 'Foo',
1033
                'year' => '1991',
1034
                '_author' => [
1035
                    'id' => 1,
1036
                    'name' => 'Dave',
1037
                ],
1038
            ],
1039
            [
1040
                'id' => 2,
1041
                'title' => 'Bar',
1042
                'year' => '1997',
1043
                '_author' => [
1044
                    'id' => 2,
1045
                    'name' => 'Bob',
1046
                ],
1047
            ],
1048
        ];
1049
1050
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
1051
        $scope = new Scope($this->manager, $resource);
1052
1053
        $expected = [
1054
            'data' => [
1055
                [
1056
                    'type' => 'books',
1057
                    'id' => '1',
1058
                    'attributes' => [
1059
                        'title' => 'Foo',
1060
                        'year' => 1991,
1061
                    ],
1062
                    'links' => [
1063
                        'self' => 'http://example.com/books/1',
1064
                    ],
1065
                ],
1066
                [
1067
                    'type' => 'books',
1068
                    'id' => '2',
1069
                    'attributes' => [
1070
                        'title' => 'Bar',
1071
                        'year' => 1997,
1072
                    ],
1073
                    'links' => [
1074
                        'self' => 'http://example.com/books/2',
1075
                    ],
1076
                ],
1077
            ],
1078
        ];
1079
1080
        $this->assertSame($expected, $scope->toArray());
1081
1082
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"links":{"self":"http:\/\/example.com\/books\/2"}}]}';
1083
        $this->assertSame($expectedJson, $scope->toJson());
1084
    }
1085
1086
    public function testSerializingItemResourceWithLinksForHasOneRelationship()
1087
    {
@@ 1086-1148 (lines=63) @@
1083
        $this->assertSame($expectedJson, $scope->toJson());
1084
    }
1085
1086
    public function testSerializingItemResourceWithLinksForHasOneRelationship()
1087
    {
1088
        $baseUrl = 'http://example.com';
1089
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1090
        $this->manager->parseIncludes('author');
1091
1092
        $bookData = [
1093
            'id' => 1,
1094
            'title' => 'Foo',
1095
            'year' => '1991',
1096
            '_author' => [
1097
                'id' => 1,
1098
                'name' => 'Dave',
1099
            ],
1100
        ];
1101
1102
        $resource = new Item($bookData, new JsonApiBookTransformer(), 'books');
1103
1104
        $scope = new Scope($this->manager, $resource);
1105
1106
        $expected = [
1107
            'data' => [
1108
                'type' => 'books',
1109
                'id' => '1',
1110
                'attributes' => [
1111
                    'title' => 'Foo',
1112
                    'year' => 1991,
1113
                ],
1114
                'relationships' => [
1115
                    'author' => [
1116
                        'links' => [
1117
                            'self' => 'http://example.com/books/1/relationships/author',
1118
                            'related' => 'http://example.com/books/1/author',
1119
                        ],
1120
                        'data' => [
1121
                            'type' => 'people',
1122
                            'id' => '1',
1123
                        ],
1124
                    ],
1125
                ],
1126
                'links' => [
1127
                    'self' => 'http://example.com/books/1',
1128
                ],
1129
            ],
1130
            'included' => [
1131
                [
1132
                    'type' => 'people',
1133
                    'id' => '1',
1134
                    'attributes' => [
1135
                        'name' => 'Dave',
1136
                    ],
1137
                    'links' => [
1138
                        'self' => 'http://example.com/people/1',
1139
                    ],
1140
                ],
1141
            ],
1142
        ];
1143
1144
        $this->assertEquals($expected, $scope->toArray());
1145
1146
        $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"},"relationships":{"author":{"links":{"self":"http:\/\/example.com\/books\/1\/relationships\/author","related":"http:\/\/example.com\/books\/1\/author"},"data":{"type":"people","id":"1"}}}},"included":[{"type":"people","id":"1","attributes":{"name":"Dave"},"links":{"self":"http:\/\/example.com\/people\/1"}}]}';
1147
        $this->assertSame($expectedJson, $scope->toJson());
1148
    }
1149
1150
    public function testSerializingItemResourceWithLinksForHasManyRelationship()
1151
    {