Symfony功能测试 - 无法保持登录状态

时间:2012-07-18 19:35:38

标签: symfony phpunit

成功使用抓取工具登录后,似乎无法保持身份验证状态。一旦我通过身份验证,我希望能够运行我的每项服务并检查收到正确的响应。

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返回登录后重定向到的页面。

1 个答案:

答案 0 :(得分:0)

我通过删除$client->followRedirects();

解决了这个问题
相关问题