Considering the isXmlHttpRequest code in the Request class and the getHeaders method in the ServerBag class, the code snippet below should do the trick:
$client->request( 'GET', '/path/to/test', array(), array(), array( 'HTTP_X-Requested-With' => 'XMLHttpRequest', ) );
I have not tested it personally, but I think it should work. The line of code below in Request used to check if the HTTP request is XmlHttpRequest .
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
In the code, $this->headers installed using:
$this->headers = new HeaderBag($this->server->getHeaders());
The getHeaders method creates an array of headers. Each server variable starting with HTTP_ , plus some special server variables, such as CONTENT_TYPE , are placed in this array.
Hope this helps.
Yours faithfully,
Matt
Matt
source share