@@ -95,14 +95,14 @@ public function testGetResolvedSchemaTemplate(): void
95
95
{ "name": "items", "type": {"type": "array", "items": "com.example.Page" }, "default": [] }
96
96
]
97
97
} ' ;
98
- $ subschemaDefinition = '{
98
+ $ subschemaDefinition = json_encode ( json_decode ( '{
99
99
"type": "record",
100
100
"namespace": "com.example",
101
101
"name": "Page",
102
102
"fields": [
103
103
{ "name": "number", "type": "int" }
104
104
]
105
- } ' ;
105
+ } ')) ;
106
106
107
107
$ expectedResult = str_replace ('"com.example.Page" ' , $ subschemaDefinition , $ rootDefinition );
108
108
@@ -134,6 +134,105 @@ public function testGetResolvedSchemaTemplate(): void
134
134
$ merger ->getResolvedSchemaTemplate ($ rootSchemaTemplate );
135
135
}
136
136
137
+ public function testGetResolvedSchemaTemplateWithEmbeddedRoot (): void
138
+ {
139
+ $ rootDefinition = '{
140
+ "type": "record",
141
+ "namespace": "com.example",
142
+ "schema_level": "root",
143
+ "name": "Library",
144
+ "fields": [
145
+ {
146
+ "name": "name",
147
+ "type": "string"
148
+ },
149
+ {
150
+ "name": "foundingYear",
151
+ "type": [
152
+ "null",
153
+ "int"
154
+ ],
155
+ "default": null
156
+ },
157
+ {
158
+ "name": "type",
159
+ "type": [
160
+ "null",
161
+ {
162
+ "name": "type",
163
+ "type": "enum",
164
+ "symbols": [
165
+ "PUBLIC",
166
+ "PRIVATE"
167
+ ]
168
+ }
169
+ ],
170
+ "default": null
171
+ },
172
+ {
173
+ "name": "collection",
174
+ "type": {
175
+ "type": "array",
176
+ "items": "com.example.Collection"
177
+ },
178
+ "default": []
179
+ },
180
+ {
181
+ "name": "archive",
182
+ "type": {
183
+ "type": "array",
184
+ "items": "com.example.Collection"
185
+ },
186
+ "default": []
187
+ }
188
+ ]
189
+ } ' ;
190
+ $ subschemaDefinition = json_encode (json_decode ('{
191
+ "type": "record",
192
+ "namespace": "com.example",
193
+ "schema_level": "root",
194
+ "name": "Collection",
195
+ "fields": [
196
+ { "name": "name", "type": "string" }
197
+ ]
198
+ } ' ));
199
+
200
+ $ subschemaDefinitionArray = \Safe \json_decode ($ subschemaDefinition , true );
201
+ unset($ subschemaDefinitionArray ['schema_level ' ]);
202
+ $ subschemaDefinitionWithoutLevel = json_encode ($ subschemaDefinitionArray );
203
+
204
+ $ subschemaId = '"com.example.Collection" ' ;
205
+ $ pos = strpos ($ rootDefinition , $ subschemaId );
206
+ $ expectedResult = substr_replace ($ rootDefinition , $ subschemaDefinitionWithoutLevel , $ pos , strlen ($ subschemaId ));
207
+
208
+ $ subschemaTemplate = $ this ->getMockForAbstractClass (SchemaTemplateInterface::class);
209
+ $ subschemaTemplate
210
+ ->expects (self ::once ())
211
+ ->method ('getSchemaDefinition ' )
212
+ ->willReturn ($ subschemaDefinition );
213
+ $ schemaRegistry = $ this ->getMockForAbstractClass (SchemaRegistryInterface::class);
214
+ $ schemaRegistry
215
+ ->expects (self ::once ())
216
+ ->method ('getSchemaById ' )
217
+ ->with ('com.example.Collection ' )
218
+ ->willReturn ($ subschemaTemplate );
219
+ $ rootSchemaTemplate = $ this ->getMockForAbstractClass (SchemaTemplateInterface::class);
220
+ $ rootSchemaTemplate
221
+ ->expects (self ::once ())
222
+ ->method ('getSchemaDefinition ' )
223
+ ->willReturn ($ rootDefinition );
224
+ $ rootSchemaTemplate
225
+ ->expects (self ::once ())
226
+ ->method ('withSchemaDefinition ' )
227
+ ->with ($ expectedResult )
228
+ ->willReturn ($ rootSchemaTemplate );
229
+
230
+ $ merger = new SchemaMerger ();
231
+ $ merger ->setSchemaRegistry ($ schemaRegistry );
232
+
233
+ $ merger ->getResolvedSchemaTemplate ($ rootSchemaTemplate );
234
+ }
235
+
137
236
public function testGetResolvedSchemaTemplateWithMultiEmbedd (): void
138
237
{
139
238
$ rootDefinition = $ this ->reformatJsonString ('{
@@ -315,14 +414,14 @@ public function testGetResolvedSchemaTemplateWithDifferentNamespaceForEmbeddedSc
315
414
{ "name": "items", "type": {"type": "array", "items": "com.example.other.Page" }, "default": [] }
316
415
]
317
416
} ' ;
318
- $ subschemaDefinition = '{
417
+ $ subschemaDefinition = json_encode ( json_decode ( '{
319
418
"type": "record",
320
419
"namespace": "com.example.other",
321
420
"name": "Page",
322
421
"fields": [
323
422
{ "name": "number", "type": "int" }
324
423
]
325
- } ' ;
424
+ } ')) ;
326
425
327
426
$ expectedResult = str_replace ('"com.example.other.Page" ' , $ subschemaDefinition , $ rootDefinition );
328
427
0 commit comments