Symfony functional testing after redirection

I'm currently trying to write functional tests, but I'm stuck after logging in and redirecting to a new page. Everything works fine until the last statement. Redirecting works fine, the content page after the redirect is fine, but I get an error on the last statement: I could not claim that false is true. I did not find anything to help me with such problems.

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

}

+4
source share
1 answer

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

$crawler = $client->followRedirect();
+7
source

Source: https://habr.com/ru/post/1616186/


All Articles