I am testing a RESTful API and need to test that the application parses incoming data properly. The type of incoming data can be in either XML or JSON format. The application looks at the Content-Type value in the header to determine how the data will be treated.
The applicatoin works well but I am not able to write a proper functional test for it in Symfony2 as I seem to be unable to set the Content-Type when calling the URL.
I am doing something like this:
$crawler = $client->request('PUT','/api/record/, array("data" => $xmlData), array(), array("Content-Type" => "text/xml"));
While it is not throwing any errors, my application is unable to pick it up. I successfully tested my script with Firefox's "Poster" plugin as well as cUrl.
Any help/idea would be greatly appreciated.
From what I can see on the Symfony2 testing section (which uses Crawler
and Client
to interact with the application), you are suppose to have it as 'CONTENT_TYPE' => 'application/xml'
. So you should try the following:
$crawler = $client->request('PUT','/api/record/', array("data" => $xmlData), array(), array('CONTENT_TYPE' => 'application/xml'));
Note that I changed it from text/xml
to application/xml
, but both should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With