Unittest Restful Api with Symfony 2
For sending an JSON Request in unittesting your symfony 2 controller/routes use HTTPACCEPT instead of ACCEPT and HTTPCONTENTTYPE insted of CONTENTTYPE.
/**
* @param string $method
* @param string $uri
* @return \Symfony\Component\BrowserKit\Response
*/
protected function sendJsonRequest($method, $uri)
{
$server = array(
'HTTP_CONTENT_TYPE' => 'application/json',
'HTTP_ACCEPT' => 'application/json',
);
$client = static::createClient();
$client->request($method, $uri, array(), array(), $server);
return $client->getResponse();
}
Written by Jan Krause
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#