Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}

}

like image 852
Osmiumbin Avatar asked Nov 17 '15 09:11

Osmiumbin


1 Answers

You must get the crawler returned by the followredirect() function:

$crawler = $client->followRedirect();
like image 100
COil Avatar answered Nov 11 '22 21:11

COil