public function testValidationNotPassed() { $content = '{"price": 50, "title": ["not a string"]}';
$payload =
new RequestPayload(50
);
$serializer =
new Serializer([new ObjectNormalizer()],
['json' =>
new JsonEncoder()]);
$validator =
$this->
createMock(ValidatorInterface::
class);
$validator->
expects($this->
once()) ->
method('validate'
) ->
with($payload) ->
willReturn(new ConstraintViolationList([new ConstraintViolation('Test', null,
[], '', null, ''
)]));
$resolver =
new RequestPayloadValueResolver($serializer,
$validator);
$argument =
new ArgumentMetadata('invalid', RequestPayload::
class, false, false, null, false,
[ MapRequestPayload::
class => new MapRequestPayload(),
]);
$request = Request::
create('/', 'POST', server:
['CONTENT_TYPE' => 'application/json'
], content:
$content);
$kernel =
$this->
createMock(HttpKernelInterface::
class);
$arguments =
$resolver->
resolve($request,
$argument);
$event =
new ControllerArgumentsEvent($kernel,
function D
) {},
$arguments,
$request, HttpKernelInterface::MAIN_REQUEST
);