无需身份验证的 Symfony2 + FOS OAuth 捆绑包测试
Symfony2 + FOS OAuth bundle testing without authentication
我有一个基于 FOSOAuthServerBundle
记录用户的应用程序,我想测试这个应用程序中的操作。
所以...在 Sf2 中有用于测试环境的特殊配置文件,config_test.yml
我已经放了这段代码:
security:
firewalls:
default:
anonymous: ~
理论上应该可以解决我的问题,因为这个防火墙允许任何人访问任何操作。我把它放在 config_test.yml
中,所以它应该只有在我测试应用程序时才能工作。很好的解决方案,我在想。
但是 Sf 抛出了这个错误:
You are not allowed to define new elements for path "security.firewalls". Please define all elements for this path in one config file.
我的问题是:
在通过 PHPUnit 测试应用程序时,如何在不登录的情况下允许访问操作?
您不能 add/define 新元素,但可以修改它们。
在 config_test.yml
中,默认防火墙使用您在 security.yml
中使用的真实防火墙的名称。
最好使用 http_basic: ~
而不是 anonymous: ~
,这样您的测试就可以像真正的经过身份验证的用户一样运行。
这里是不错的食谱:http://symfony.com/doc/2.8/cookbook/testing/http_authentication.html
我有一个基于 FOSOAuthServerBundle
记录用户的应用程序,我想测试这个应用程序中的操作。
所以...在 Sf2 中有用于测试环境的特殊配置文件,config_test.yml
我已经放了这段代码:
security:
firewalls:
default:
anonymous: ~
理论上应该可以解决我的问题,因为这个防火墙允许任何人访问任何操作。我把它放在 config_test.yml
中,所以它应该只有在我测试应用程序时才能工作。很好的解决方案,我在想。
但是 Sf 抛出了这个错误:
You are not allowed to define new elements for path "security.firewalls". Please define all elements for this path in one config file.
我的问题是: 在通过 PHPUnit 测试应用程序时,如何在不登录的情况下允许访问操作?
您不能 add/define 新元素,但可以修改它们。
在 config_test.yml
中,默认防火墙使用您在 security.yml
中使用的真实防火墙的名称。
最好使用 http_basic: ~
而不是 anonymous: ~
,这样您的测试就可以像真正的经过身份验证的用户一样运行。
这里是不错的食谱:http://symfony.com/doc/2.8/cookbook/testing/http_authentication.html