@@ -125,6 +125,37 @@ public function testDenormalize()
125
125
$ this ->assertInstanceOf (Dummy::class, $ normalizer ->denormalize (['name ' => 'hello ' ], Dummy::class, null , $ context ));
126
126
}
127
127
128
+ public function testDenormalizeWithIri ()
129
+ {
130
+ $ context = ['resource_class ' => Dummy::class, 'api_allow_update ' => true ];
131
+
132
+ $ propertyNameCollection = new PropertyNameCollection (['name ' ]);
133
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
134
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->willReturn ($ propertyNameCollection )->shouldBeCalled ();
135
+
136
+ $ propertyMetadataFactory = new PropertyMetadata (null , null , true );
137
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
138
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'name ' , [])->willReturn ($ propertyMetadataFactory )->shouldBeCalled ();
139
+
140
+ $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
141
+ $ iriConverterProphecy ->getItemFromIri ('/dummies/12 ' , ['resource_class ' => Dummy::class, 'api_allow_update ' => true , 'fetch_data ' => false ])->shouldBeCalled ();
142
+
143
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
144
+
145
+ $ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
146
+ $ serializerProphecy ->willImplement (DenormalizerInterface::class);
147
+
148
+ $ normalizer = new ItemNormalizer (
149
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
150
+ $ propertyMetadataFactoryProphecy ->reveal (),
151
+ $ iriConverterProphecy ->reveal (),
152
+ $ resourceClassResolverProphecy ->reveal ()
153
+ );
154
+ $ normalizer ->setSerializer ($ serializerProphecy ->reveal ());
155
+
156
+ $ this ->assertInstanceOf (Dummy::class, $ normalizer ->denormalize (['@id ' => '/dummies/12 ' , 'id ' => '12 ' , 'name ' => 'hello ' ], Dummy::class, null , $ context ));
157
+ }
158
+
128
159
/**
129
160
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
130
161
* @expectedExceptionMessage Update is not allowed for this operation.
@@ -151,6 +182,6 @@ public function testDenormalizeWithIdAndUpdateNotAllowed()
151
182
$ resourceClassResolverProphecy ->reveal ()
152
183
);
153
184
$ normalizer ->setSerializer ($ serializerProphecy ->reveal ());
154
- $ normalizer ->denormalize (['id ' => '/dummies/12 ' , 'name ' => 'hello ' ], Dummy::class, null , $ context );
185
+ $ normalizer ->denormalize (['@ id ' => '/dummies/12 ' , ' id ' => ' 12 ' , 'name ' => 'hello ' ], Dummy::class, null , $ context );
155
186
}
156
187
}
0 commit comments