Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set Content-Type with Symfony2 Functional Tests

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.

like image 852
user975068 Avatar asked Jun 07 '12 16:06

user975068


1 Answers

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.

like image 190
Jeppe Mariager-Lam Avatar answered Sep 22 '22 13:09

Jeppe Mariager-Lam