Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Unit testing: How to simulate a Http-PUT with a json body?

I use the client-Object to simulate and test my Silex-Webservices. How can I send a JSON-Body with the PUT-method?

My idea was:

$crawler = $this->client->request('PUT', '/test', array(), array(), array(), '{"id":"34"}');

That does not work. :(

like image 955
user1879408 Avatar asked Mar 10 '13 18:03

user1879408


1 Answers

Please try to use this code:

$client->request(
    'PUT', '/test', array(), array(),
    array(
        'CONTENT_TYPE' => 'application/json',
        'HTTP_X-Requested-With' => 'XMLHttpRequest'
    ),
    '{"id":"34"}'
);  
like image 142
Dimitry Orgonov Avatar answered Nov 01 '22 12:11

Dimitry Orgonov