|
36 | 36 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
37 | 37 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
38 | 38 | use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
| 39 | +use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer; |
39 | 40 | use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
40 | 41 | use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
|
41 | 42 | use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
63 | 64 | use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
|
64 | 65 | use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
|
65 | 66 | use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
|
| 67 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumConstructor; |
66 | 68 | use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
|
67 | 69 | use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer;
|
68 | 70 |
|
@@ -1165,6 +1167,47 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
|
1165 | 1167 | $this->assertSame($expected, $exceptionsAsArray);
|
1166 | 1168 | }
|
1167 | 1169 |
|
| 1170 | + /** |
| 1171 | + * @requires PHP 8.1 |
| 1172 | + */ |
| 1173 | + public function testCollectDenormalizationErrorsWithEnumConstructor() |
| 1174 | + { |
| 1175 | + $serializer = new Serializer( |
| 1176 | + [ |
| 1177 | + new BackedEnumNormalizer(), |
| 1178 | + new ObjectNormalizer(), |
| 1179 | + ], |
| 1180 | + ['json' => new JsonEncoder()] |
| 1181 | + ); |
| 1182 | + |
| 1183 | + try { |
| 1184 | + $serializer->deserialize('{"invalid": "get"}', DummyObjectWithEnumConstructor::class, 'json', [ |
| 1185 | + DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true |
| 1186 | + ]); |
| 1187 | + } |
| 1188 | + catch (\Throwable $th) { |
| 1189 | + $this->assertInstanceOf(PartialDenormalizationException::class, $th); |
| 1190 | + } |
| 1191 | + |
| 1192 | + $exceptionsAsArray = array_map(function (NotNormalizableValueException $e): array { |
| 1193 | + return [ |
| 1194 | + 'currentType' => $e->getCurrentType(), |
| 1195 | + 'useMessageForUser' => $e->canUseMessageForUser(), |
| 1196 | + 'message' => $e->getMessage(), |
| 1197 | + ]; |
| 1198 | + }, $th->getErrors()); |
| 1199 | + |
| 1200 | + $expected = [ |
| 1201 | + [ |
| 1202 | + 'currentType' => 'array', |
| 1203 | + 'useMessageForUser' => true, |
| 1204 | + 'message' => 'Failed to create object because the object miss the "get" property.', |
| 1205 | + ], |
| 1206 | + ]; |
| 1207 | + |
| 1208 | + $this->assertSame($expected, $exceptionsAsArray); |
| 1209 | + } |
| 1210 | + |
1168 | 1211 | public function provideCollectDenormalizationErrors()
|
1169 | 1212 | {
|
1170 | 1213 | return [
|
|
0 commit comments