|
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\ConstraintViolationList;
|
31 | 34 | use Symfony\Component\Validator\Exception\ValidationFailedException;
|
@@ -332,6 +335,34 @@ public function testRequestContentValidationPassed()
|
332 | 335 | $this->assertEquals([$payload], $event->getArguments());
|
333 | 336 | }
|
334 | 337 |
|
| 338 | + /** |
| 339 | + * @testWith [null] |
| 340 | + * [[]] |
| 341 | + */ |
| 342 | + public function testRequestContentWithUntypedErrors(?array $types) |
| 343 | + { |
| 344 | + $this->expectException(HttpException::class); |
| 345 | + $this->expectExceptionMessage('This value was of an unexpected type.'); |
| 346 | + $serializer = $this->createMock(SerializerDenormalizer::class); |
| 347 | + |
| 348 | + if (null === $types) { |
| 349 | + $exception = new NotNormalizableValueException('Error with no types'); |
| 350 | + } else { |
| 351 | + $exception = NotNormalizableValueException::createForUnexpectedDataType('Error with no types', '', []); |
| 352 | + } |
| 353 | + $serializer->method('deserialize')->willThrowException(new PartialDenormalizationException([], [$exception])); |
| 354 | + |
| 355 | + $resolver = new RequestPayloadValueResolver($serializer, $this->createMock(ValidatorInterface::class)); |
| 356 | + $request = Request::create('/', 'POST', server: ['CONTENT_TYPE' => 'application/json'], content: '{"price": 50}'); |
| 357 | + |
| 358 | + $arguments = $resolver->resolve($request, new ArgumentMetadata('valid', RequestPayload::class, false, false, null, false, [ |
| 359 | + MapRequestPayload::class => new MapRequestPayload(), |
| 360 | + ])); |
| 361 | + $event = new ControllerArgumentsEvent($this->createMock(HttpKernelInterface::class), function () {}, $arguments, $request, HttpKernelInterface::MAIN_REQUEST); |
| 362 | + |
| 363 | + $resolver->onKernelControllerArguments($event); |
| 364 | + } |
| 365 | + |
335 | 366 | public function testQueryStringValidationPassed()
|
336 | 367 | {
|
337 | 368 | $payload = new RequestPayload(50);
|
@@ -638,6 +669,10 @@ public function __construct(public readonly float $price)
|
638 | 669 | }
|
639 | 670 | }
|
640 | 671 |
|
| 672 | +interface SerializerDenormalizer extends SerializerInterface, DenormalizerInterface |
| 673 | +{ |
| 674 | +} |
| 675 | + |
641 | 676 | class User
|
642 | 677 | {
|
643 | 678 | public function __construct(
|
|
0 commit comments