Symfony functional testing asserting after redirect

I am currently trying to write functional tests but i'm getting stuck after logging in and redirecting to a new page. Everything works ok until last assert. The redirect works ok,the content page after redirect is ok, but i get an error on last assert: failed asserting that false is true. I found nothing to help me from similar issues here.

Here's the code:

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
    $client = static::createClient(array(),
        array(
            'HTTP_HOST' => 'locahost'

        ));



    $crawler = $client->request('GET', '/login');
    echo $client->getRequest()->getUri();


    $form = $crawler->selectButton('Login')->form(array(
        '_username' => 'user',
        '_password' => 'pass',
    ),'POST');


    $client->submit($form);
    $this->assertTrue($client->getResponse()->isRedirect());
    $client->followRedirect();
    echo $client->getRequest()->getUri();

    print_r( $client->getResponse()->getContent());


    $this->assertTrue($crawler->filter('html:contains("New")')->count() > 0);
}

}


您必须获取followredirect()函数返回的followredirect()

$crawler = $client->followRedirect();
链接地址: http://www.djcxy.com/p/67804.html

上一篇: ServletContext getContextPath()

下一篇: Symfony功能测试在重定向后声明