|
15 | 15 |
|
16 | 16 | use ApiPlatform\Api\IriConverterInterface;
|
17 | 17 | use ApiPlatform\Api\ResourceClassResolverInterface;
|
18 |
| -use ApiPlatform\Api\UrlGeneratorInterface; |
19 |
| -use ApiPlatform\Exception\InvalidArgumentException; |
20 | 18 | use ApiPlatform\Metadata\ApiProperty;
|
21 |
| -use ApiPlatform\Metadata\ApiResource; |
22 |
| -use ApiPlatform\Metadata\Get; |
23 |
| -use ApiPlatform\Metadata\Link; |
24 |
| -use ApiPlatform\Metadata\Operations; |
25 | 19 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
26 | 20 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
|
27 | 21 | use ApiPlatform\Metadata\Property\PropertyNameCollection;
|
28 |
| -use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
29 |
| -use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; |
30 | 22 | use ApiPlatform\Serializer\ItemNormalizer;
|
31 | 23 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
|
32 | 24 | use PHPUnit\Framework\TestCase;
|
@@ -189,69 +181,6 @@ public function testDenormalizeWithIri(): void
|
189 | 181 | $this->assertInstanceOf(Dummy::class, $normalizer->denormalize(['id' => '/dummies/12', 'name' => 'hello'], Dummy::class, null, $context));
|
190 | 182 | }
|
191 | 183 |
|
192 |
| - public function testDenormalizeGuessingUriVariables(): void |
193 |
| - { |
194 |
| - $context = ['resource_class' => Dummy::class, 'api_allow_update' => true, 'uri_variables' => [ |
195 |
| - 'parent_resource' => '1', |
196 |
| - 'resource' => '1', |
197 |
| - ]]; |
198 |
| - |
199 |
| - $propertyNameCollection = new PropertyNameCollection(['name']); |
200 |
| - $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
201 |
| - $propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::cetera())->willReturn($propertyNameCollection)->shouldBeCalled(); |
202 |
| - |
203 |
| - $propertyMetadata = (new ApiProperty())->withReadable(true)->withWritable(true); |
204 |
| - $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
205 |
| - $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::cetera())->willReturn($propertyMetadata)->shouldBeCalled(); |
206 |
| - |
207 |
| - $uriVariables = [ |
208 |
| - 'parent_resource' => new Link('parent_resource', identifiers: ['id']), |
209 |
| - 'resource' => new Link('resource', identifiers: ['id']), |
210 |
| - 'sub_resource' => new Link('sub_resource', identifiers: ['id']), |
211 |
| - ]; |
212 |
| - $resourceMetadataCollectionFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); |
213 |
| - $resourceMetadataCollectionFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadataCollection(Dummy::class, [ |
214 |
| - (new ApiResource())->withShortName('Dummy')->withOperations(new Operations([ |
215 |
| - 'sub_resource' => (new Get(uriVariables: $uriVariables))->withShortName('Dummy'), |
216 |
| - ])), |
217 |
| - ])); |
218 |
| - |
219 |
| - $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); |
220 |
| - $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class); |
221 |
| - $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true); |
222 |
| - |
223 |
| - $serializerProphecy = $this->prophesize(SerializerInterface::class); |
224 |
| - $serializerProphecy->willImplement(DenormalizerInterface::class); |
225 |
| - |
226 |
| - $iriConverterProphecy = $this->prophesize(IriConverterInterface::class); |
227 |
| - $iriConverterProphecy->getResourceFromIri(Argument::is('12'), Argument::cetera())->willThrow(InvalidArgumentException::class); |
228 |
| - $iriConverterProphecy |
229 |
| - ->getIriFromResource( |
230 |
| - Dummy::class, |
231 |
| - UrlGeneratorInterface::ABS_PATH, |
232 |
| - Argument::type(Get::class), |
233 |
| - Argument::withEntry('uri_variables', Argument::allOf( |
234 |
| - Argument::withEntry('parent_resource', '1'), |
235 |
| - Argument::withEntry('resource', '1'), |
236 |
| - Argument::withEntry('sub_resource', '12') |
237 |
| - )) |
238 |
| - ) |
239 |
| - ->willReturn('parent_resource/1/resource/1/sub_resource/2') |
240 |
| - ->shouldBeCalledOnce(); |
241 |
| - $iriConverterProphecy->getResourceFromIri('parent_resource/1/resource/1/sub_resource/2', ['fetch_data' => true])->shouldBeCalledOnce(); |
242 |
| - |
243 |
| - $normalizer = new ItemNormalizer( |
244 |
| - $propertyNameCollectionFactoryProphecy->reveal(), |
245 |
| - $propertyMetadataFactoryProphecy->reveal(), |
246 |
| - $iriConverterProphecy->reveal(), |
247 |
| - $resourceClassResolverProphecy->reveal(), |
248 |
| - resourceMetadataFactory: $resourceMetadataCollectionFactoryProphecy->reveal(), |
249 |
| - ); |
250 |
| - $normalizer->setSerializer($serializerProphecy->reveal()); |
251 |
| - |
252 |
| - $this->assertInstanceOf(Dummy::class, $normalizer->denormalize(['id' => '12', 'name' => 'hello'], Dummy::class, null, $context)); |
253 |
| - } |
254 |
| - |
255 | 184 | public function testDenormalizeWithIdAndUpdateNotAllowed(): void
|
256 | 185 | {
|
257 | 186 | $this->expectException(NotNormalizableValueException::class);
|
|
0 commit comments