|
23 | 23 | use Symfony\Component\HttpKernel\HttpKernelInterface;
|
24 | 24 | use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
25 | 25 | use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
| 26 | +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; |
26 | 27 | use Symfony\Component\Serializer\Exception\PartialDenormalizationException;
|
| 28 | +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
27 | 29 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
28 | 30 | use Symfony\Component\Serializer\Serializer;
|
| 31 | +use Symfony\Component\Serializer\SerializerInterface; |
29 | 32 | use Symfony\Component\Validator\Constraints as Assert;
|
30 | 33 | use Symfony\Component\Validator\ConstraintViolation;
|
31 | 34 | use Symfony\Component\Validator\ConstraintViolationList;
|
@@ -307,6 +310,25 @@ public function testRequestContentValidationPassed()
|
307 | 310 | $this->assertEquals([$payload], $event->getArguments());
|
308 | 311 | }
|
309 | 312 |
|
| 313 | + public function testRequestContentWithUntypedErrors() |
| 314 | + { |
| 315 | + $this->expectException(HttpException::class); |
| 316 | + $serializer = $this->createMock(SerializerDenormalizer::class); |
| 317 | + $serializer->method('deserialize')->willThrowException(new PartialDenormalizationException([], [new NotNormalizableValueException('Error with no types')])); |
| 318 | + |
| 319 | + $resolver = new RequestPayloadValueResolver($serializer, $this->createMock(ValidatorInterface::class)); |
| 320 | + $argument = new ArgumentMetadata('valid', RequestPayload::class, false, false, null, false, [ |
| 321 | + MapRequestPayload::class => new MapRequestPayload(), |
| 322 | + ]); |
| 323 | + $request = Request::create('/', 'POST', server: ['CONTENT_TYPE' => 'application/json'], content: '{"price": 50}'); |
| 324 | + |
| 325 | + $kernel = $this->createMock(HttpKernelInterface::class); |
| 326 | + $arguments = $resolver->resolve($request, $argument); |
| 327 | + $event = new ControllerArgumentsEvent($kernel, function () {}, $arguments, $request, HttpKernelInterface::MAIN_REQUEST); |
| 328 | + |
| 329 | + $resolver->onKernelControllerArguments($event); |
| 330 | + } |
| 331 | + |
310 | 332 | public function testQueryStringValidationPassed()
|
311 | 333 | {
|
312 | 334 | $payload = new RequestPayload(50);
|
@@ -612,3 +634,6 @@ public function __construct(public readonly float $price)
|
612 | 634 | {
|
613 | 635 | }
|
614 | 636 | }
|
| 637 | + |
| 638 | +interface SerializerDenormalizer extends SerializerInterface, DenormalizerInterface |
| 639 | +{} |
0 commit comments