何らかの理由で、新しい $client->request を送信すると、指定したヘッダーが失われます:
public function testGetClientsAction()
{
$client = static::createClient();
$cookie = new Cookie('locale2', 'en', time() + 3600 * 24 * 7, '/', null, false, false);
$client->getCookieJar()->set($cookie);
// Visit user login page and login
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('login')->form();
$crawler = $client->submit($form, array('_username' => 'greg', '_password' => 'greg'));
$client->request(
'GET',
'/clients',
array(),
array(),
array('X-Requested-With' => 'XMLHttpRequest', 'accept' => 'application/json')
);
print_r($client->getResponse());
die();
}
テストされているメソッドでは、最初の行にこれがあります:
print_r($request->headers->all());
応答は次のとおりです。
Array
(
[host] => Array
(
[0] => localhost
)
[user-agent] => Array
(
[0] => Symfony2 BrowserKit
)
[accept] => Array
(
[0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
)
[accept-language] => Array
(
[0] => en-us,en;q=0.5
)
[accept-charset] => Array
(
[0] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
)
[referer] => Array
(
[0] => http://localhost/login_check
)
[x-php-ob-level] => Array
(
[0] => 1
)
)