@@ -101,6 +101,30 @@ public function testGetItemFromIri()
101
101
$ this ->assertEquals ($ converter ->getItemFromIri ('/users/3 ' , ['fetch_data ' => true ]), $ item );
102
102
}
103
103
104
+ public function testGetItemFromIriWithOperationName ()
105
+ {
106
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
107
+
108
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
109
+
110
+ $ itemDataProviderProphecy = $ this ->prophesize (ItemDataProviderInterface::class);
111
+ $ itemDataProviderProphecy ->getItem ('AppBundle\Entity\User ' , '3 ' , 'operation_name ' , ['fetch_data ' => true ])
112
+ ->willReturn ('foo ' )
113
+ ->shouldBeCalledTimes (1 );
114
+
115
+ $ routeNameResolverProphecy = $ this ->prophesize (RouteNameResolverInterface::class);
116
+
117
+ $ routerProphecy = $ this ->prophesize (RouterInterface::class);
118
+ $ routerProphecy ->match ('/users/3 ' )->willReturn ([
119
+ '_api_resource_class ' => 'AppBundle\Entity\User ' ,
120
+ '_api_item_operation_name ' => 'operation_name ' ,
121
+ 'id ' => 3 ,
122
+ ])->shouldBeCalledTimes (1 );
123
+
124
+ $ converter = $ this ->getIriConverter ($ routerProphecy , null , $ itemDataProviderProphecy );
125
+ $ this ->assertEquals ($ converter ->getItemFromIri ('/users/3 ' , ['fetch_data ' => true ]), 'foo ' );
126
+ }
127
+
104
128
public function testGetIriFromResourceClass ()
105
129
{
106
130
$ routeNameResolverProphecy = $ this ->prophesize (RouteNameResolverInterface::class);
@@ -199,7 +223,7 @@ public function testGetItemFromIriWithIdentifierDenormalizer()
199
223
'id ' => 3 ,
200
224
])->shouldBeCalledTimes (1 );
201
225
202
- $ converter = $ this ->getIriConverter ($ routerProphecy , null , $ itemDataProviderProphecy , $ identifierDenormalizerProphecy );
226
+ $ converter = $ this ->getIriConverter ($ routerProphecy , null , $ itemDataProviderProphecy , null , $ identifierDenormalizerProphecy );
203
227
$ this ->assertEquals ($ converter ->getItemFromIri ('/users/3 ' , ['fetch_data ' => true ]), $ item );
204
228
}
205
229
@@ -216,11 +240,9 @@ public function testGetItemFromIriWithSubresourceDataProvider()
216
240
'_api_subresource_operation_name ' => 'get_subresource ' ,
217
241
'id ' => 3 ,
218
242
])->shouldBeCalledTimes (1 );
219
- $ identifierDenormalizerProphecy = $ this ->prophesize (ChainIdentifierDenormalizer::class);
220
- $ identifierDenormalizerProphecy ->denormalize ('3 ' , Dummy::class)->shouldBeCalled ()->willReturn (['id ' => 3 ]);
221
243
$ subresourceDataProviderProphecy = $ this ->prophesize (SubresourceDataProviderInterface::class);
222
- $ subresourceDataProviderProphecy ->getSubresource (Dummy::class, ['id ' => [ ' id ' => 3 ]] , $ subresourceContext + ['fetch_data ' => true , ChainIdentifierDenormalizer:: HAS_IDENTIFIER_DENORMALIZER => true ], 'get_subresource ' )->shouldBeCalled ()->willReturn ($ item );
223
- $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , $ identifierDenormalizerProphecy , $ subresourceDataProviderProphecy );
244
+ $ subresourceDataProviderProphecy ->getSubresource (Dummy::class, ['id ' => 3 ] , $ subresourceContext + ['fetch_data ' => true ], 'get_subresource ' )->shouldBeCalled ()->willReturn ($ item );
245
+ $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , $ subresourceDataProviderProphecy );
224
246
$ this ->assertEquals ($ converter ->getItemFromIri ('/users/3/adresses ' , ['fetch_data ' => true ]), $ item );
225
247
}
226
248
@@ -244,7 +266,7 @@ public function testGetItemFromIriWithSubresourceDataProviderNotFound()
244
266
$ identifierDenormalizerProphecy ->denormalize ('3 ' , Dummy::class)->shouldBeCalled ()->willReturn (['id ' => 3 ]);
245
267
$ subresourceDataProviderProphecy = $ this ->prophesize (SubresourceDataProviderInterface::class);
246
268
$ subresourceDataProviderProphecy ->getSubresource (Dummy::class, ['id ' => ['id ' => 3 ]], $ subresourceContext + ['fetch_data ' => true , ChainIdentifierDenormalizer::HAS_IDENTIFIER_DENORMALIZER => true ], 'get_subresource ' )->shouldBeCalled ()->willReturn (null );
247
- $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , $ identifierDenormalizerProphecy , $ subresourceDataProviderProphecy );
269
+ $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , $ subresourceDataProviderProphecy , $ identifierDenormalizerProphecy );
248
270
$ converter ->getItemFromIri ('/users/3/adresses ' , ['fetch_data ' => true ]);
249
271
}
250
272
@@ -265,7 +287,7 @@ public function testGetItemFromIriBadIdentifierException()
265
287
])->shouldBeCalledTimes (1 );
266
288
$ identifierDenormalizerProphecy = $ this ->prophesize (ChainIdentifierDenormalizer::class);
267
289
$ identifierDenormalizerProphecy ->denormalize ('3 ' , Dummy::class)->shouldBeCalled ()->willThrow (new InvalidIdentifierException ('fail ' ));
268
- $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , $ identifierDenormalizerProphecy );
290
+ $ converter = $ this ->getIriConverter ($ routerProphecy , $ routeNameResolverProphecy , null , null , $ identifierDenormalizerProphecy );
269
291
$ this ->assertEquals ($ converter ->getItemFromIri ('/users/3 ' , ['fetch_data ' => true ]), $ item );
270
292
}
271
293
@@ -302,7 +324,7 @@ private function getResourceClassResolver()
302
324
return $ resourceClassResolver ->reveal ();
303
325
}
304
326
305
- private function getIriConverter ($ routerProphecy = null , $ routeNameResolverProphecy = null , $ itemDataProviderProphecy = null , $ identifierDenormalizerProphecy = null , $ subresourceDataProviderProphecy = null )
327
+ private function getIriConverter ($ routerProphecy = null , $ routeNameResolverProphecy = null , $ itemDataProviderProphecy = null , $ subresourceDataProviderProphecy = null , $ identifierDenormalizerProphecy = null )
306
328
{
307
329
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
308
330
$ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
@@ -328,8 +350,8 @@ private function getIriConverter($routerProphecy = null, $routeNameResolverProph
328
350
$ routerProphecy ->reveal (),
329
351
null ,
330
352
new IdentifiersExtractor ($ propertyNameCollectionFactory , $ propertyMetadataFactory , null , $ this ->getResourceClassResolver ()),
331
- $ identifierDenormalizerProphecy ? $ identifierDenormalizerProphecy ->reveal () : null ,
332
- $ subresourceDataProviderProphecy ? $ subresourceDataProviderProphecy ->reveal () : null
353
+ $ subresourceDataProviderProphecy ? $ subresourceDataProviderProphecy ->reveal () : null ,
354
+ $ identifierDenormalizerProphecy ? $ identifierDenormalizerProphecy ->reveal () : null
333
355
);
334
356
}
335
357
}
0 commit comments