我已经安装了FosUserBundle,我想用PhpUnit进行测试,检查用户是否可以登录,但我的代码一定是错的,因为我无法重定向。
我的代码:
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}
答案 0 :(得分:1)
您似乎正在使用client
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
//here you're using $this->client not $client
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}