ShinDarth ShinDarth - 1 year ago 145
PHP Question

Symfony unit test: how to set the request content type?

When creating a unit test with phpunit and Symfony (extending

class), I need to perform a request specifying the content-type.

So I have my client:

$client->request('POST', '/my/route');

but the request content-type defaults to
, how can I change it?

E.g. setting it to

Answer Source

You have to add the content type in the fifth parameter:

$client->request('POST', '/my/route', [], [], ['CONTENT_TYPE' => 'application/json']);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download