概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:49:15 | 115 次阅读 | 评论: 0 | 来源: 网络整理

If your application needs HTTP authentication, pass the username and password as server variables to createClient():

$client = static::createClient(array(), array(
    'PHP_AUTH_USER' => 'username',
    'PHP_AUTH_PW'   => 'pa$$word',
));

You can also override it on a per request basis:

$client->request('DELETE', '/post/12', array(), array(), array(
    'PHP_AUTH_USER' => 'username',
    'PHP_AUTH_PW'   => 'pa$$word',
));

When your application is using a form_login, you can simplify your tests by allowing your test configuration to make use of HTTP authentication. This way you can use the above to authenticate in tests, but still have your users log in via the normal form_login. The trick is to include the http_basic key in your firewall, along with the form_login key:

  • YAML
    # app/config/config_test.yml
    security:
        firewalls:
            your_firewall_name:
                http_basic: ~
    
  • XML
    <!-- app/config/config_test.xml -->
    <security:config>
        <security:firewall name="your_firewall_name">
          <security:http-basic />
       </security:firewall>
    </security:config>
    
  • PHP
    // app/config/config_test.php
    $container->loadFromExtension('security', array(
        'firewalls' => array(
            'your_firewall_name' => array(
                'http_basic' => array(),
            ),
        ),
    ));
    
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务