|
18 | 18 | use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
|
19 | 19 | use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
|
20 | 20 | use ApiPlatform\Core\Exception\InvalidArgumentException;
|
| 21 | +use ApiPlatform\Core\Exception\ItemNotFoundException; |
21 | 22 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
22 | 23 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
|
23 | 24 | use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
|
@@ -822,6 +823,63 @@ public function testChildInheritedProperty()
|
822 | 823 |
|
823 | 824 | public function testDenormalizeRelationWithPlainId()
|
824 | 825 | {
|
| 826 | + $relatedDummy = new RelatedDummy(); |
| 827 | + |
| 828 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 829 | + $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn( |
| 830 | + new PropertyNameCollection(['relatedDummy']) |
| 831 | + )->shouldBeCalled(); |
| 832 | + |
| 833 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 834 | + $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn( |
| 835 | + new PropertyMetadata( |
| 836 | + new Type(Type::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class), |
| 837 | + '', |
| 838 | + false, |
| 839 | + true, |
| 840 | + false, |
| 841 | + false |
| 842 | + ) |
| 843 | + )->shouldBeCalled(); |
| 844 | + |
| 845 | + $iriConverterProphecy = $this->prophesize(IriConverterInterface::class); |
| 846 | + $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class); |
| 847 | + $propertyAccessorProphecy->setValue(Argument::type(Dummy::class), 'relatedDummy', $relatedDummy)->shouldBeCalled(); |
| 848 | + |
| 849 | + $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); |
| 850 | + $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true)->shouldBeCalled(); |
| 851 | + |
| 852 | + $serializerProphecy = $this->prophesize(SerializerInterface::class); |
| 853 | + $serializerProphecy->willImplement(DenormalizerInterface::class); |
| 854 | + |
| 855 | + $itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class); |
| 856 | + $itemDataProviderProphecy->getItem(RelatedDummy::class, 1, null, Argument::type('array'))->willReturn($relatedDummy)->shouldBeCalled(); |
| 857 | + |
| 858 | + $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [ |
| 859 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 860 | + $propertyMetadataFactoryProphecy->reveal(), |
| 861 | + $iriConverterProphecy->reveal(), |
| 862 | + $resourceClassResolverProphecy->reveal(), |
| 863 | + $propertyAccessorProphecy->reveal(), |
| 864 | + null, |
| 865 | + null, |
| 866 | + $itemDataProviderProphecy->reveal(), |
| 867 | + true, |
| 868 | + [], |
| 869 | + null, |
| 870 | + null, |
| 871 | + true, |
| 872 | + ]); |
| 873 | + $normalizer->setSerializer($serializerProphecy->reveal()); |
| 874 | + |
| 875 | + $normalizer->denormalize(['relatedDummy' => 1], Dummy::class, 'jsonld'); |
| 876 | + } |
| 877 | + |
| 878 | + public function testDenormalizeRelationWithPlainIdNotFound() |
| 879 | + { |
| 880 | + $this->expectException(ItemNotFoundException::class); |
| 881 | + $this->expectExceptionMessage('Item not found for "1".'); |
| 882 | + |
825 | 883 | $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
|
826 | 884 | $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(
|
827 | 885 | new PropertyNameCollection(['relatedDummy'])
|
@@ -849,7 +907,7 @@ public function testDenormalizeRelationWithPlainId()
|
849 | 907 | $serializerProphecy->willImplement(DenormalizerInterface::class);
|
850 | 908 |
|
851 | 909 | $itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class);
|
852 |
| - $itemDataProviderProphecy->getItem(RelatedDummy::class, 1, null, Argument::type('array'))->shouldBeCalled(); |
| 910 | + $itemDataProviderProphecy->getItem(RelatedDummy::class, 1, null, Argument::type('array'))->willReturn(null)->shouldBeCalled(); |
853 | 911 |
|
854 | 912 | $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [
|
855 | 913 | $propertyNameCollectionFactoryProphecy->reveal(),
|
|
0 commit comments