|
41 | 41 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyForAdditionalFieldsInput;
|
42 | 42 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritance;
|
43 | 43 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceChild;
|
| 44 | +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\NonCloneableDummy; |
44 | 45 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
|
45 | 46 | use ApiPlatform\Tests\Fixtures\TestBundle\Entity\SecuredDummy;
|
46 | 47 | use Doctrine\Common\Collections\ArrayCollection;
|
@@ -1702,6 +1703,56 @@ public function testDenormalizeCollectionDecodedFromXmlWithOneChild()
|
1702 | 1703 |
|
1703 | 1704 | $normalizer->denormalize($data, Dummy::class, 'xml');
|
1704 | 1705 | }
|
| 1706 | + |
| 1707 | + public function testDenormalizePopulatingNonCloneableObject() |
| 1708 | + { |
| 1709 | + $dummy = new NonCloneableDummy(); |
| 1710 | + $dummy->setName('foo'); |
| 1711 | + |
| 1712 | + $data = [ |
| 1713 | + 'name' => 'bar', |
| 1714 | + ]; |
| 1715 | + |
| 1716 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 1717 | + $propertyNameCollectionFactoryProphecy->create(NonCloneableDummy::class, [])->willReturn(new PropertyNameCollection(['name'])); |
| 1718 | + |
| 1719 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 1720 | + $propertyMetadataFactoryProphecy->create(NonCloneableDummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true)); |
| 1721 | + |
| 1722 | + $iriConverterProphecy = $this->prophesize(IriConverterInterface::class); |
| 1723 | + $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class); |
| 1724 | + $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); |
| 1725 | + $resourceClassResolverProphecy->getResourceClass(null, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class); |
| 1726 | + $resourceClassResolverProphecy->getResourceClass($dummy, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class); |
| 1727 | + $resourceClassResolverProphecy->isResourceClass(NonCloneableDummy::class)->willReturn(true); |
| 1728 | + |
| 1729 | + $serializerProphecy = $this->prophesize(SerializerInterface::class); |
| 1730 | + $serializerProphecy->willImplement(NormalizerInterface::class); |
| 1731 | + |
| 1732 | + $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [ |
| 1733 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 1734 | + $propertyMetadataFactoryProphecy->reveal(), |
| 1735 | + $iriConverterProphecy->reveal(), |
| 1736 | + $resourceClassResolverProphecy->reveal(), |
| 1737 | + $propertyAccessorProphecy->reveal(), |
| 1738 | + null, |
| 1739 | + null, |
| 1740 | + null, |
| 1741 | + false, |
| 1742 | + [], |
| 1743 | + [], |
| 1744 | + null, |
| 1745 | + null, |
| 1746 | + ]); |
| 1747 | + $normalizer->setSerializer($serializerProphecy->reveal()); |
| 1748 | + |
| 1749 | + $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy]; |
| 1750 | + $actual = $normalizer->denormalize($data, NonCloneableDummy::class, null, $context); |
| 1751 | + |
| 1752 | + $this->assertInstanceOf(NonCloneableDummy::class, $actual); |
| 1753 | + $this->assertSame($dummy, $actual); |
| 1754 | + $propertyAccessorProphecy->setValue($actual, 'name', 'bar')->shouldHaveBeenCalled(); |
| 1755 | + } |
1705 | 1756 | }
|
1706 | 1757 |
|
1707 | 1758 | class ObjectWithBasicProperties
|
|
0 commit comments