You should be able to do the following:
1) "view" on the page
$client = static::createClient(); $crawler = $client->request('GET', '/login');
2) Select a form via the submit button
$buttonCrawlerNode = $crawler->selectButton('submit');
3) Pass the login credentials as data and submit the form
$form = $buttonCrawlerNode->form(); $data = array('username' => ' u@u.com ','password' => 'pass'); $client->submit($form,$data);
4) Follow the forwarding
$crawler = $client->followRedirect();
5) At this point you can check the response code
$this->assertEquals(302, $client->getResponse()->getStatusCode());
or access a secure page
$crawler = $client->request('GET', '/dashboard');
Tim arney
source share