@@ -484,16 +484,34 @@ public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMe
484484
485485 public function testExceptionWhenTypeIsNotKnownInDiscriminator ()
486486 {
487- $ this ->expectException (RuntimeException::class);
488- $ this ->expectExceptionMessage ('The type "second" has no mapped class for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface" ' );
489- $ this ->serializerWithClassDiscriminator ()->deserialize ('{"type":"second","one":1} ' , DummyMessageInterface::class, 'json ' );
487+ try {
488+ $ this ->serializerWithClassDiscriminator ()->deserialize ('{"type":"second","one":1} ' , DummyMessageInterface::class, 'json ' );
489+
490+ $ this ->fail ();
491+ } catch (\Throwable $ e ) {
492+ $ this ->assertInstanceOf (NotNormalizableValueException::class, $ e );
493+ $ this ->assertSame ('The type "second" is not a valid value. ' , $ e ->getMessage ());
494+ $ this ->assertSame ('string ' , $ e ->getCurrentType ());
495+ $ this ->assertSame (['string ' ], $ e ->getExpectedTypes ());
496+ $ this ->assertSame ('type ' , $ e ->getPath ());
497+ $ this ->assertTrue ($ e ->canUseMessageForUser ());
498+ }
490499 }
491500
492501 public function testExceptionWhenTypeIsNotInTheBodyToDeserialiaze ()
493502 {
494- $ this ->expectException (RuntimeException::class);
495- $ this ->expectExceptionMessage ('Type property "type" not found for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface" ' );
496- $ this ->serializerWithClassDiscriminator ()->deserialize ('{"one":1} ' , DummyMessageInterface::class, 'json ' );
503+ try {
504+ $ this ->serializerWithClassDiscriminator ()->deserialize ('{"one":1} ' , DummyMessageInterface::class, 'json ' );
505+
506+ $ this ->fail ();
507+ } catch (\Throwable $ e ) {
508+ $ this ->assertInstanceOf (NotNormalizableValueException::class, $ e );
509+ $ this ->assertSame ('Type property "type" not found for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface". ' , $ e ->getMessage ());
510+ $ this ->assertSame ('null ' , $ e ->getCurrentType ());
511+ $ this ->assertSame (['string ' ], $ e ->getExpectedTypes ());
512+ $ this ->assertSame ('type ' , $ e ->getPath ());
513+ $ this ->assertFalse ($ e ->canUseMessageForUser ());
514+ }
497515 }
498516
499517 public function testNotNormalizableValueExceptionMessageForAResource ()
@@ -744,7 +762,9 @@ public function testCollectDenormalizationErrors()
744762 "string": null
745763 }
746764 ],
747- "php74FullWithConstructor": {}
765+ "php74FullWithConstructor": {},
766+ "dummyMessage": {
767+ }
748768 } ' ;
749769
750770 $ classMetadataFactory = new ClassMetadataFactory (new AnnotationLoader (new AnnotationReader ()));
@@ -893,6 +913,15 @@ public function testCollectDenormalizationErrors()
893913 'useMessageForUser ' => true ,
894914 'message ' => 'Failed to create object because the object miss the "constructorArgument" property. ' ,
895915 ],
916+ [
917+ 'currentType ' => 'null ' ,
918+ 'expectedTypes ' => [
919+ 'string ' ,
920+ ],
921+ 'path ' => 'dummyMessage.type ' ,
922+ 'useMessageForUser ' => false ,
923+ 'message ' => 'Type property "type" not found for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface". ' ,
924+ ],
896925 ];
897926
898927 $ this ->assertSame ($ expected , $ exceptionsAsArray );
0 commit comments