14
14
namespace ApiPlatform \Tests \JsonApi \Serializer ;
15
15
16
16
use ApiPlatform \Api \ResourceClassResolverInterface ;
17
- use ApiPlatform \Core \Metadata \Resource \Factory \ResourceMetadataFactoryInterface ;
18
- use ApiPlatform \Core \Metadata \Resource \ResourceMetadata ;
19
17
use ApiPlatform \JsonApi \Serializer \CollectionNormalizer ;
18
+ use ApiPlatform \Metadata \ApiResource ;
19
+ use ApiPlatform \Metadata \GetCollection ;
20
+ use ApiPlatform \Metadata \Operations ;
21
+ use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
22
+ use ApiPlatform \Metadata \Resource \ResourceMetadataCollection ;
20
23
use ApiPlatform \State \Pagination \PaginatorInterface ;
21
24
use ApiPlatform \State \Pagination \PartialPaginatorInterface ;
22
25
use ApiPlatform \Tests \ProphecyTrait ;
@@ -35,7 +38,7 @@ class CollectionNormalizerTest extends TestCase
35
38
public function testSupportsNormalize ()
36
39
{
37
40
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
38
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface ::class);
41
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface ::class);
39
42
40
43
$ normalizer = new CollectionNormalizer ($ resourceClassResolverProphecy ->reveal (), 'page ' , $ resourceMetadataFactoryProphecy ->reveal ());
41
44
@@ -63,12 +66,17 @@ public function testNormalizePaginator()
63
66
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
64
67
$ resourceClassResolverProphecy ->getResourceClass ($ paginator , 'Foo ' )->willReturn ('Foo ' );
65
68
66
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
67
- $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata ());
69
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
70
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadataCollection ('Foo ' , [
71
+ (new ApiResource ())
72
+ ->withShortName ('Foo ' )
73
+ ->withOperations (new Operations (['get ' => (new GetCollection ())]))
74
+ ]));
68
75
69
76
$ itemNormalizer = $ this ->prophesize (NormalizerInterface::class);
70
77
$ itemNormalizer ->normalize ('foo ' , CollectionNormalizer::FORMAT , [
71
78
'request_uri ' => '/foos?page=3 ' ,
79
+ 'operation_name ' => 'get ' ,
72
80
'uri ' => 'http://example.com/foos?page=3 ' ,
73
81
'api_sub_level ' => true ,
74
82
'resource_class ' => 'Foo ' ,
@@ -113,6 +121,7 @@ public function testNormalizePaginator()
113
121
114
122
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ paginator , CollectionNormalizer::FORMAT , [
115
123
'request_uri ' => '/foos?page=3 ' ,
124
+ 'operation_name ' => 'get ' ,
116
125
'uri ' => 'http://example.com/foos?page=3 ' ,
117
126
'resource_class ' => 'Foo ' ,
118
127
]));
@@ -134,12 +143,17 @@ public function testNormalizePartialPaginator()
134
143
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
135
144
$ resourceClassResolverProphecy ->getResourceClass ($ paginator , 'Foo ' )->willReturn ('Foo ' );
136
145
137
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
138
- $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata ());
146
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
147
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadataCollection ('Foo ' , [
148
+ (new ApiResource ())
149
+ ->withShortName ('Foo ' )
150
+ ->withOperations (new Operations (['get ' => (new GetCollection ())]))
151
+ ]));
139
152
140
153
$ itemNormalizer = $ this ->prophesize (NormalizerInterface::class);
141
154
$ itemNormalizer ->normalize ('foo ' , CollectionNormalizer::FORMAT , [
142
155
'request_uri ' => '/foos?page=3 ' ,
156
+ 'operation_name ' => 'get ' ,
143
157
'uri ' => 'http://example.com/foos?page=3 ' ,
144
158
'api_sub_level ' => true ,
145
159
'resource_class ' => 'Foo ' ,
@@ -181,6 +195,7 @@ public function testNormalizePartialPaginator()
181
195
182
196
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ paginator , CollectionNormalizer::FORMAT , [
183
197
'request_uri ' => '/foos?page=3 ' ,
198
+ 'operation_name ' => 'get ' ,
184
199
'uri ' => 'http://example.com/foos?page=3 ' ,
185
200
'resource_class ' => 'Foo ' ,
186
201
]));
@@ -192,11 +207,16 @@ public function testNormalizeArray()
192
207
193
208
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
194
209
$ resourceClassResolverProphecy ->getResourceClass ($ data , 'Foo ' )->willReturn ('Foo ' );
195
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
196
- $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata ());
210
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
211
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadataCollection ('Foo ' , [
212
+ (new ApiResource ())
213
+ ->withShortName ('Foo ' )
214
+ ->withOperations (new Operations (['get ' => (new GetCollection ())]))
215
+ ]));
197
216
$ itemNormalizer = $ this ->prophesize (NormalizerInterface::class);
198
217
$ itemNormalizer ->normalize ('foo ' , CollectionNormalizer::FORMAT , [
199
218
'request_uri ' => '/foos ' ,
219
+ 'operation_name ' => 'get ' ,
200
220
'uri ' => 'http://example.com/foos ' ,
201
221
'api_sub_level ' => true ,
202
222
'resource_class ' => 'Foo ' ,
@@ -231,6 +251,7 @@ public function testNormalizeArray()
231
251
232
252
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ data , CollectionNormalizer::FORMAT , [
233
253
'request_uri ' => '/foos ' ,
254
+ 'operation_name ' => 'get ' ,
234
255
'uri ' => 'http://example.com/foos ' ,
235
256
'resource_class ' => 'Foo ' ,
236
257
]));
@@ -243,12 +264,17 @@ public function testNormalizeIncludedData()
243
264
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
244
265
$ resourceClassResolverProphecy ->getResourceClass ($ data , 'Foo ' )->willReturn ('Foo ' );
245
266
246
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
247
- $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata ());
267
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
268
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadataCollection ('Foo ' , [
269
+ (new ApiResource ())
270
+ ->withShortName ('Foo ' )
271
+ ->withOperations (new Operations (['get ' => (new GetCollection ())]))
272
+ ]));
248
273
249
274
$ itemNormalizer = $ this ->prophesize (NormalizerInterface::class);
250
275
$ itemNormalizer ->normalize ('foo ' , CollectionNormalizer::FORMAT , [
251
276
'request_uri ' => '/foos ' ,
277
+ 'operation_name ' => 'get ' ,
252
278
'uri ' => 'http://example.com/foos ' ,
253
279
'api_sub_level ' => true ,
254
280
'resource_class ' => 'Foo ' ,
@@ -303,6 +329,7 @@ public function testNormalizeIncludedData()
303
329
304
330
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ data , CollectionNormalizer::FORMAT , [
305
331
'request_uri ' => '/foos ' ,
332
+ 'operation_name ' => 'get ' ,
306
333
'uri ' => 'http://example.com/foos ' ,
307
334
'resource_class ' => 'Foo ' ,
308
335
]));
@@ -318,12 +345,17 @@ public function testNormalizeWithoutDataKey()
318
345
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
319
346
$ resourceClassResolverProphecy ->getResourceClass ($ data , 'Foo ' )->willReturn ('Foo ' );
320
347
321
- $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
322
- $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata ());
348
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
349
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadataCollection ('Foo ' , [
350
+ (new ApiResource ())
351
+ ->withShortName ('Foo ' )
352
+ ->withOperations (new Operations (['get ' => (new GetCollection ())]))
353
+ ]));
323
354
324
355
$ itemNormalizer = $ this ->prophesize (NormalizerInterface::class);
325
356
$ itemNormalizer ->normalize ('foo ' , CollectionNormalizer::FORMAT , [
326
357
'request_uri ' => '/foos ' ,
358
+ 'operation_name ' => 'get ' ,
327
359
'uri ' => 'http://example.com/foos ' ,
328
360
'api_sub_level ' => true ,
329
361
'resource_class ' => 'Foo ' ,
@@ -334,6 +366,7 @@ public function testNormalizeWithoutDataKey()
334
366
335
367
$ normalizer ->normalize ($ data , CollectionNormalizer::FORMAT , [
336
368
'request_uri ' => '/foos ' ,
369
+ 'operation_name ' => 'get ' ,
337
370
'uri ' => 'http://example.com/foos ' ,
338
371
'resource_class ' => 'Foo ' ,
339
372
]);
0 commit comments