Symfony module testing: how to simulate Http-PUT using json body?

I use client-Object to model and test my Silex-Webservices. How can I send a JSON body using the PUT method?

My idea:

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

This does not work.: (

+4
source share
2 answers

Try using this code:

 $client->request( 'PUT', '/test', array(), array(), array( 'CONTENT_TYPE' => 'application/json', 'HTTP_X-Requested-With' => 'XMLHttpRequest' ), '{"id":"34"}' ); 
+8
source

Thanks to Dimitry, not exactly what I was looking for, but a great hint to find a solution:

 $client->request( 'PUT', '/test', array(), array(), array( 'CONTENT_TYPE' => 'application/json', 'HTTP_X-Requested-With' => 'XMLHttpRequest' ), '{"id":"34"}' ); 

Your solution had one empty array, and the idea was to pass JSON as a string!

Thanks a lot! Greetings

0
source

All Articles