|
21 | 21 | use ApiPlatform\Metadata\Property\PropertyNameCollection;
|
22 | 22 | use ApiPlatform\Serializer\AbstractItemNormalizer;
|
23 | 23 | use ApiPlatform\Symfony\Security\ResourceAccessCheckerInterface;
|
| 24 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5584\DtoWithNullValue; |
24 | 25 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
|
25 | 26 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritance;
|
26 | 27 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceChild;
|
@@ -1347,6 +1348,48 @@ public function testDenormalizePopulatingNonCloneableObject(): void
|
1347 | 1348 | $this->assertSame($dummy, $actual);
|
1348 | 1349 | $propertyAccessorProphecy->setValue($actual, 'name', 'bar')->shouldHaveBeenCalled();
|
1349 | 1350 | }
|
| 1351 | + |
| 1352 | + public function testDenormalizeObjectWithNullDisabledTypeEnforcement(): void |
| 1353 | + { |
| 1354 | + $data = [ |
| 1355 | + 'dummy' => null, |
| 1356 | + ]; |
| 1357 | + |
| 1358 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 1359 | + $propertyNameCollectionFactoryProphecy->create(DtoWithNullValue::class, [])->willReturn(new PropertyNameCollection(['dummy'])); |
| 1360 | + |
| 1361 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 1362 | + $propertyMetadataFactoryProphecy->create(DtoWithNullValue::class, 'dummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_OBJECT, nullable: true)])->withDescription('')->withReadable(true)->withWritable(true)); |
| 1363 | + |
| 1364 | + $iriConverterProphecy = $this->prophesize(IriConverterInterface::class); |
| 1365 | + $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class); |
| 1366 | + $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); |
| 1367 | + $resourceClassResolverProphecy->getResourceClass(null, DtoWithNullValue::class)->willReturn(DtoWithNullValue::class); |
| 1368 | + $resourceClassResolverProphecy->isResourceClass(DtoWithNullValue::class)->willReturn(true); |
| 1369 | + |
| 1370 | + $serializerProphecy = $this->prophesize(SerializerInterface::class); |
| 1371 | + $serializerProphecy->willImplement(NormalizerInterface::class); |
| 1372 | + |
| 1373 | + $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [ |
| 1374 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 1375 | + $propertyMetadataFactoryProphecy->reveal(), |
| 1376 | + $iriConverterProphecy->reveal(), |
| 1377 | + $resourceClassResolverProphecy->reveal(), |
| 1378 | + $propertyAccessorProphecy->reveal(), |
| 1379 | + null, |
| 1380 | + null, |
| 1381 | + [], |
| 1382 | + null, |
| 1383 | + null, |
| 1384 | + ]); |
| 1385 | + $normalizer->setSerializer($serializerProphecy->reveal()); |
| 1386 | + |
| 1387 | + $context = [AbstractItemNormalizer::DISABLE_TYPE_ENFORCEMENT => true]; |
| 1388 | + $actual = $normalizer->denormalize($data, DtoWithNullValue::class, null, $context); |
| 1389 | + |
| 1390 | + $this->assertInstanceOf(DtoWithNullValue::class, $actual); |
| 1391 | + $this->assertEquals(new DtoWithNullValue(), $actual); |
| 1392 | + } |
1350 | 1393 | }
|
1351 | 1394 |
|
1352 | 1395 | class ObjectWithBasicProperties
|
|
0 commit comments