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);
}
}
You must get the crawler returned by the followredirect()
function:
$crawler = $client->followRedirect();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With