如何登录测试内部才能执行用户特定的操作?
最佳答案
实际上,身份验证必须像真实用户一样进行。在这种情况下,您必须知道纯密码并填写登录表单
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class XXX extends WebTestCase {
public function testUserLogin() {
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('_submit')->form(array(
'_username' => 'user',
'_password' => 'pa$$word',
));
$client->submit($form);
$crawler = $client->followRedirect(); // "/" page
// if credentials were correct, you should be logged in and ready to test your app
}
}
关于unit-testing - Symfony2登录FOS UserBundle进行功能测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9182831/