60
60
use Symfony \Component \Serializer \Tests \Fixtures \DummyMessageNumberOne ;
61
61
use Symfony \Component \Serializer \Tests \Fixtures \DummyMessageNumberTwo ;
62
62
use Symfony \Component \Serializer \Tests \Fixtures \DummyObjectWithEnumConstructor ;
63
+ use Symfony \Component \Serializer \Tests \Fixtures \DummyObjectWithEnumProperty ;
63
64
use Symfony \Component \Serializer \Tests \Fixtures \FalseBuiltInDummy ;
64
65
use Symfony \Component \Serializer \Tests \Fixtures \NormalizableTraversableDummy ;
65
66
use Symfony \Component \Serializer \Tests \Fixtures \Php74Full ;
@@ -1230,7 +1231,48 @@ public function testCollectDenormalizationErrorsWithEnumConstructor()
1230
1231
/**
1231
1232
* @requires PHP 8.1
1232
1233
*/
1233
- public function testNoCollectDenormalizationErrorsWithWrongEnum ()
1234
+ public function testCollectDenormalizationErrorsWithWrongPropertyWithoutConstruct ()
1235
+ {
1236
+ $ classMetadataFactory = new ClassMetadataFactory (new AnnotationLoader ());
1237
+ $ reflectionExtractor = new ReflectionExtractor ();
1238
+ $ propertyInfoExtractor = new PropertyInfoExtractor ([], [$ reflectionExtractor ], [], [], []);
1239
+
1240
+ $ serializer = new Serializer (
1241
+ [
1242
+ new BackedEnumNormalizer (),
1243
+ new ObjectNormalizer ($ classMetadataFactory , null , null , $ propertyInfoExtractor ),
1244
+ ],
1245
+ ['json ' => new JsonEncoder ()]
1246
+ );
1247
+
1248
+ try {
1249
+ $ serializer ->deserialize ('{"get": "POST"} ' , DummyObjectWithEnumProperty::class, 'json ' , [
1250
+ DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true ,
1251
+ ]);
1252
+ } catch (\Throwable $ th ) {
1253
+ $ this ->assertInstanceOf (PartialDenormalizationException::class, $ th );
1254
+ }
1255
+
1256
+ $ exceptionsAsArray = array_map (function (NotNormalizableValueException $ e ): array {
1257
+ return [
1258
+ 'message ' => $ e ->getMessage (),
1259
+ ];
1260
+ }, $ th ->getErrors ());
1261
+
1262
+ $ expected = [
1263
+ [
1264
+ 'message ' => 'The data must belong to a backed enumeration of type Symfony\Component\Serializer\Tests\Fixtures\StringBackedEnumDummy '
1265
+
1266
+ ],
1267
+ ];
1268
+
1269
+ $ this ->assertSame ($ expected , $ exceptionsAsArray );
1270
+ }
1271
+
1272
+ /**
1273
+ * @requires PHP 8.1
1274
+ */
1275
+ public function testNoCollectDenormalizationErrorsWithWrongEnumOnConstructor ()
1234
1276
{
1235
1277
$ serializer = new Serializer (
1236
1278
[
@@ -1241,7 +1283,7 @@ public function testNoCollectDenormalizationErrorsWithWrongEnum()
1241
1283
);
1242
1284
1243
1285
try {
1244
- $ serializer ->deserialize ('{"get": "invalid "} ' , DummyObjectWithEnumConstructor::class, 'json ' , [
1286
+ $ serializer ->deserialize ('{"get": "POST "} ' , DummyObjectWithEnumConstructor::class, 'json ' , [
1245
1287
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true ,
1246
1288
]);
1247
1289
} catch (\Throwable $ th ) {
0 commit comments