简体   繁体   English

Symfony2:对在security.interactive_login事件中设置了会话变量的控制器的功能测试

[英]Symfony2: Functional Testing for Controllers with Session Variables Set in security.interactive_login Event

I have implemented a listener on the security.interactive_login event to set one session variable that is used all over my app, as advised in Symfony2: After successful login event, perform set of actions . 我已经在security.interactive_login事件上实现了一个侦听器,以设置一个在我的应用程序中使用的会话变量,如Symfony2中所建议:成功登录事件后,执行一组操作 The problem is that the security.interactive_login event is not fired in functional tests (I guess this is logical since there is no actual interactive login). 问题在于在功能测试中不会触发security.interactive_login事件(由于没有实际的交互式登录,所以我认为这是合乎逻辑的)。 Given this restriction: How can I run functional tests with session variables set upon user login? 有此限制:如何在用户登录后设置会话变量来运行功能测试?

如果您使用基本身份验证,则可以最终手动触发事件处理程序进行测试,但是我认为更合适的方法是通过使用登录表单与客户端提交来登录应用程序-应该以这种方式触发事件监听器。

Just to bring detail on the workaround: 只是为了详细介绍解决方法:

In the functional test case I changed 在功能测试用例中,我进行了更改

$client = static::createClient(array(), array(
    'PHP_AUTH_USER'=>'alberto'
    ,'PHP_AUTH_PW'=>'********'
    )
);

For 对于

$client = static::createClient();
$crawler = $client->request('GET','/secured/login');
$form = $crawler->selectButton('Aceptar')->form();
$form['_username'] = 'alberto';
$form['_password'] = '********';
$crawler = $client->submit($form);      

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM