|  | 
| 43 | 43 | use Symfony\Component\Serializer\Tests\Fixtures\Attributes\GroupDummy; | 
| 44 | 44 | use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy; | 
| 45 | 45 | use Symfony\Component\Serializer\Tests\Fixtures\DummyPrivatePropertyWithoutGetter; | 
|  | 46 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion; | 
| 46 | 47 | use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy; | 
| 47 | 48 | use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy; | 
| 48 | 49 | use Symfony\Component\Serializer\Tests\Fixtures\Php74DummyPrivate; | 
|  | 
| 65 | 66 | use Symfony\Component\Serializer\Tests\Normalizer\Features\TypedPropertiesObject; | 
| 66 | 67 | use Symfony\Component\Serializer\Tests\Normalizer\Features\TypedPropertiesObjectWithGetters; | 
| 67 | 68 | use Symfony\Component\Serializer\Tests\Normalizer\Features\TypeEnforcementTestTrait; | 
|  | 69 | +use Symfony\Component\TypeInfo\Type; | 
| 68 | 70 | 
 | 
| 69 | 71 | /** | 
| 70 | 72 |  * @author Kévin Dunglas <dunglas@gmail.com> | 
| @@ -346,6 +348,27 @@ public function testConstructorWithUnknownObjectTypeHintDenormalize() | 
| 346 | 348 |         $normalizer->denormalize($data, DummyWithConstructorInexistingObject::class); | 
| 347 | 349 |     } | 
| 348 | 350 | 
 | 
|  | 351 | +    public function testConstructorWithNotMatchingUnionTypes() | 
|  | 352 | +    { | 
|  | 353 | +        $data = [ | 
|  | 354 | +            'value' => 'string', | 
|  | 355 | +            'value2' => 'string', | 
|  | 356 | +        ]; | 
|  | 357 | +        $normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()), null, null, new PropertyInfoExtractor([], [new ReflectionExtractor()])); | 
|  | 358 | + | 
|  | 359 | +        $this->expectException(NotNormalizableValueException::class); | 
|  | 360 | + | 
|  | 361 | +        if (class_exists(Type::class) && method_exists(PropertyInfoExtractor::class, 'getType')) { | 
|  | 362 | +            $this->expectExceptionMessage('The type of the "value" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion" must be one of "float", "int" ("string" given).'); | 
|  | 363 | +        } else { | 
|  | 364 | +            $this->expectExceptionMessage('The type of the "value" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion" must be one of "int", "float" ("string" given).'); | 
|  | 365 | +        } | 
|  | 366 | + | 
|  | 367 | +        $normalizer->denormalize($data, DummyWithUnion::class, 'xml', [ | 
|  | 368 | +            AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, | 
|  | 369 | +        ]); | 
|  | 370 | +    } | 
|  | 371 | + | 
| 349 | 372 |     // attributes | 
| 350 | 373 | 
 | 
| 351 | 374 |     protected function getNormalizerForAttributes(): ObjectNormalizer | 
|  | 
0 commit comments