You need the prefix of the actual HTTP_ header, no need to use HTTP_CUSTOM:
$server = array('HTTP_X-Requested-With' => 'XMLHttpRequest'); $this->call('get', '/ajax-route', array(), array(), $server);
Alternative syntax that looks a little better IMO:
$this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest'); $this->call('get', '/ajax-route');
Here are some sample code for the JSON headers ( Request::isJson() and Request::wantsJson() ):
$this->client->setServerParameter('HTTP_CONTENT_TYPE', 'application/json'); $this->call('get', '/is-json'); $this->client->setServerParameter('HTTP_ACCEPT', 'application/json'); $this->call('get', '/wants-json');
Here is a useful helper method that you can add to your test system:
protected function prepareAjaxJsonRequest() { $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest'); $this->client->setServerParameter('HTTP_CONTENT_TYPE', 'application/json'); $this->client->setServerParameter('HTTP_ACCEPT', 'application/json'); }
source share