|  | 
| 21 | 21 | use Symfony\Component\PropertyInfo\PropertyInfoExtractor; | 
| 22 | 22 | use Symfony\Component\Serializer\Attribute\Ignore; | 
| 23 | 23 | use Symfony\Component\Serializer\Exception\LogicException; | 
|  | 24 | +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; | 
| 24 | 25 | use Symfony\Component\Serializer\Exception\RuntimeException; | 
| 25 | 26 | use Symfony\Component\Serializer\Exception\UnexpectedValueException; | 
| 26 | 27 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; | 
|  | 
| 41 | 42 | use Symfony\Component\Serializer\Tests\Fixtures\Attributes\GroupDummy; | 
| 42 | 43 | use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy; | 
| 43 | 44 | use Symfony\Component\Serializer\Tests\Fixtures\DummyPrivatePropertyWithoutGetter; | 
|  | 45 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion; | 
| 44 | 46 | use Symfony\Component\Serializer\Tests\Fixtures\FormatAndContextAwareNormalizer; | 
| 45 | 47 | use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy; | 
| 46 | 48 | use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy; | 
| @@ -343,6 +345,22 @@ public function testConstructorWithUnknownObjectTypeHintDenormalize() | 
| 343 | 345 |         $normalizer->denormalize($data, DummyWithConstructorInexistingObject::class); | 
| 344 | 346 |     } | 
| 345 | 347 | 
 | 
|  | 348 | +    public function testConstructorWithNotMatchingUnionTypes() | 
|  | 349 | +    { | 
|  | 350 | +        $data = [ | 
|  | 351 | +            'value' => 'string', | 
|  | 352 | +            'value2' => 'string', | 
|  | 353 | +        ]; | 
|  | 354 | +        $normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()), null, null, new PropertyInfoExtractor([], [new ReflectionExtractor()])); | 
|  | 355 | + | 
|  | 356 | +        $this->expectException(NotNormalizableValueException::class); | 
|  | 357 | +        $this->expectExceptionMessage('The type of the "value" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion" must be one of "int", "float" ("string" given).'); | 
|  | 358 | + | 
|  | 359 | +        $normalizer->denormalize($data, DummyWithUnion::class, 'xml', [ | 
|  | 360 | +            AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, | 
|  | 361 | +        ]); | 
|  | 362 | +    } | 
|  | 363 | + | 
| 346 | 364 |     // attributes | 
| 347 | 365 | 
 | 
| 348 | 366 |     protected function getNormalizerForAttributes(): ObjectNormalizer | 
|  | 
0 commit comments