|
26 | 26 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritance;
|
27 | 27 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceChild;
|
28 | 28 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceRelated;
|
| 29 | +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\NonCloneableDummy; |
29 | 30 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
|
30 | 31 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\SecuredDummy;
|
31 | 32 | use Doctrine\Common\Collections\ArrayCollection;
|
@@ -1296,6 +1297,56 @@ public function testDenormalizeCollectionDecodedFromXmlWithOneChild(): void
|
1296 | 1297 |
|
1297 | 1298 | $normalizer->denormalize($data, Dummy::class, 'xml');
|
1298 | 1299 | }
|
| 1300 | + |
| 1301 | + public function testDenormalizePopulatingNonCloneableObject() |
| 1302 | + { |
| 1303 | + $dummy = new NonCloneableDummy(); |
| 1304 | + $dummy->setName('foo'); |
| 1305 | + |
| 1306 | + $data = [ |
| 1307 | + 'name' => 'bar', |
| 1308 | + ]; |
| 1309 | + |
| 1310 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 1311 | + $propertyNameCollectionFactoryProphecy->create(NonCloneableDummy::class, [])->willReturn(new PropertyNameCollection(['name'])); |
| 1312 | + |
| 1313 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 1314 | + $propertyMetadataFactoryProphecy->create(NonCloneableDummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true)); |
| 1315 | + |
| 1316 | + $iriConverterProphecy = $this->prophesize(IriConverterInterface::class); |
| 1317 | + $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class); |
| 1318 | + $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); |
| 1319 | + $resourceClassResolverProphecy->getResourceClass(null, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class); |
| 1320 | + $resourceClassResolverProphecy->getResourceClass($dummy, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class); |
| 1321 | + $resourceClassResolverProphecy->isResourceClass(NonCloneableDummy::class)->willReturn(true); |
| 1322 | + |
| 1323 | + $serializerProphecy = $this->prophesize(SerializerInterface::class); |
| 1324 | + $serializerProphecy->willImplement(NormalizerInterface::class); |
| 1325 | + |
| 1326 | + $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [ |
| 1327 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 1328 | + $propertyMetadataFactoryProphecy->reveal(), |
| 1329 | + $iriConverterProphecy->reveal(), |
| 1330 | + $resourceClassResolverProphecy->reveal(), |
| 1331 | + $propertyAccessorProphecy->reveal(), |
| 1332 | + null, |
| 1333 | + null, |
| 1334 | + null, |
| 1335 | + false, |
| 1336 | + [], |
| 1337 | + [], |
| 1338 | + null, |
| 1339 | + null, |
| 1340 | + ]); |
| 1341 | + $normalizer->setSerializer($serializerProphecy->reveal()); |
| 1342 | + |
| 1343 | + $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy]; |
| 1344 | + $actual = $normalizer->denormalize($data, NonCloneableDummy::class, null, $context); |
| 1345 | + |
| 1346 | + $this->assertInstanceOf(NonCloneableDummy::class, $actual); |
| 1347 | + $this->assertSame($dummy, $actual); |
| 1348 | + $propertyAccessorProphecy->setValue($actual, 'name', 'bar')->shouldHaveBeenCalled(); |
| 1349 | + } |
1299 | 1350 | }
|
1300 | 1351 |
|
1301 | 1352 | class ObjectWithBasicProperties
|
|
0 commit comments