|
24 | 24 | use Symfony\Component\Serializer\Exception\ExtraAttributesException;
|
25 | 25 | use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
26 | 26 | use Symfony\Component\Serializer\Exception\LogicException;
|
| 27 | +use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException; |
27 | 28 | use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
28 | 29 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
|
29 | 30 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
|
|
38 | 39 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
39 | 40 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
40 | 41 | use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
|
| 42 | +use Symfony\Component\Serializer\Normalizer\CustomNormalizer; |
41 | 43 | use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
42 | 44 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
43 | 45 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
|
49 | 51 | use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummySecondChild;
|
50 | 52 | use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
|
51 | 53 | use Symfony\Component\Serializer\Tests\Fixtures\DummySecondChildQuux;
|
| 54 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithNotNormalizable; |
| 55 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrBool; |
| 56 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrNull; |
52 | 57 | use Symfony\Component\Serializer\Tests\Normalizer\Features\ObjectDummyWithContextAttribute;
|
53 | 58 |
|
54 | 59 | class AbstractObjectNormalizerTest extends TestCase
|
@@ -835,6 +840,36 @@ public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
|
835 | 840 | $test = $normalizer->denormalize($data, $obj::class);
|
836 | 841 | $this->assertSame('nested-id', $test->id);
|
837 | 842 | }
|
| 843 | + |
| 844 | + public function testDenormalizeUntypedFormat() |
| 845 | + { |
| 846 | + $serializer = new Serializer([new ObjectNormalizer(propertyTypeExtractor: new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 847 | + $actual = $serializer->denormalize(['value' => ''], DummyWithObjectOrNull::class, 'xml'); |
| 848 | + |
| 849 | + $this->assertEquals(new DummyWithObjectOrNull(null), $actual); |
| 850 | + } |
| 851 | + |
| 852 | + public function testDenormalizeUntypedFormatNotNormalizable() |
| 853 | + { |
| 854 | + $this->expectException(NotNormalizableValueException::class); |
| 855 | + $serializer = new Serializer([new CustomNormalizer(), new ObjectNormalizer(propertyTypeExtractor: new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 856 | + $serializer->denormalize(['value' => 'test'], DummyWithNotNormalizable::class, 'xml'); |
| 857 | + } |
| 858 | + |
| 859 | + public function testDenormalizeUntypedFormatMissingArg() |
| 860 | + { |
| 861 | + $this->expectException(MissingConstructorArgumentsException::class); |
| 862 | + $serializer = new Serializer([new ObjectNormalizer(propertyTypeExtractor: new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 863 | + $serializer->denormalize(['value' => 'invalid'], DummyWithObjectOrNull::class, 'xml'); |
| 864 | + } |
| 865 | + |
| 866 | + public function testDenormalizeUntypedFormatScalar() |
| 867 | + { |
| 868 | + $serializer = new Serializer([new ObjectNormalizer(propertyTypeExtractor: new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 869 | + $actual = $serializer->denormalize(['value' => 'false'], DummyWithObjectOrBool::class, 'xml'); |
| 870 | + |
| 871 | + $this->assertEquals(new DummyWithObjectOrBool(false), $actual); |
| 872 | + } |
838 | 873 | }
|
839 | 874 |
|
840 | 875 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
|
0 commit comments