0
成功使用爬虫登录后,我似乎无法保持身份验证。一旦我通过身份验证,我希望能够贯穿每个服务并检查接收到的正确响应。Symfony功能测试 - 无法保持登录状态
public function testGetClientsAction()
{
$client = static::createClient();
$client->followRedirects();
$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->insulate();
$client->request(
'GET',
'/clients/12345',
array(),
array(),
array('X-Requested-With' => "XMLHttpRequest")
);
print_r($client->getResponse()->getContent());
die();
}
print_r返回重定向到登录后的页面。