|
14 | 14 | use Doctrine\Common\Annotations\AnnotationReader;
|
15 | 15 | use PHPUnit\Framework\TestCase;
|
16 | 16 | use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
|
| 17 | +use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; |
| 18 | +use Symfony\Component\PropertyInfo\PropertyInfoExtractor; |
17 | 19 | use Symfony\Component\PropertyInfo\Type;
|
18 | 20 | use Symfony\Component\Serializer\Exception\ExtraAttributesException;
|
19 | 21 | use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
20 | 22 | use Symfony\Component\Serializer\Exception\LogicException;
|
| 23 | +use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException; |
21 | 24 | use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
22 | 25 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
|
23 | 26 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
|
|
29 | 32 | use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
30 | 33 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
31 | 34 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
| 35 | +use Symfony\Component\Serializer\Normalizer\CustomNormalizer; |
32 | 36 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
33 | 37 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
34 | 38 | use Symfony\Component\Serializer\Serializer;
|
|
39 | 43 | use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummySecondChild;
|
40 | 44 | use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
|
41 | 45 | use Symfony\Component\Serializer\Tests\Fixtures\DummySecondChildQuux;
|
| 46 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithNotNormalizable; |
| 47 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrBool; |
| 48 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrNull; |
42 | 49 |
|
43 | 50 | class AbstractObjectNormalizerTest extends TestCase
|
44 | 51 | {
|
@@ -444,6 +451,36 @@ public function testNormalizeEmptyObject()
|
444 | 451 | $normalizedData = $normalizer->normalize(new EmptyDummy(), 'any', ['preserve_empty_objects' => true]);
|
445 | 452 | $this->assertEquals(new \ArrayObject(), $normalizedData);
|
446 | 453 | }
|
| 454 | + |
| 455 | + public function testDenormalizeUntypedFormat() |
| 456 | + { |
| 457 | + $serializer = new Serializer([new ObjectNormalizer(null, null, null, new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 458 | + $actual = $serializer->denormalize(['value' => ''], DummyWithObjectOrNull::class, 'xml'); |
| 459 | + |
| 460 | + $this->assertEquals(new DummyWithObjectOrNull(null), $actual); |
| 461 | + } |
| 462 | + |
| 463 | + public function testDenormalizeUntypedFormatNotNormalizable() |
| 464 | + { |
| 465 | + $this->expectException(NotNormalizableValueException::class); |
| 466 | + $serializer = new Serializer([new CustomNormalizer(), new ObjectNormalizer(null, null, null, new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 467 | + $serializer->denormalize(['value' => 'test'], DummyWithNotNormalizable::class, 'xml'); |
| 468 | + } |
| 469 | + |
| 470 | + public function testDenormalizeUntypedFormatMissingArg() |
| 471 | + { |
| 472 | + $this->expectException(MissingConstructorArgumentsException::class); |
| 473 | + $serializer = new Serializer([new ObjectNormalizer(null, null, null, new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 474 | + $serializer->denormalize(['value' => 'invalid'], DummyWithObjectOrNull::class, 'xml'); |
| 475 | + } |
| 476 | + |
| 477 | + public function testDenormalizeUntypedFormatScalar() |
| 478 | + { |
| 479 | + $serializer = new Serializer([new ObjectNormalizer(null, null, null, new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]))]); |
| 480 | + $actual = $serializer->denormalize(['value' => 'false'], DummyWithObjectOrBool::class, 'xml'); |
| 481 | + |
| 482 | + $this->assertEquals(new DummyWithObjectOrBool(false), $actual); |
| 483 | + } |
447 | 484 | }
|
448 | 485 |
|
449 | 486 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
|
0 commit comments