如何在 symfony 1.4 的功能性石灰测试中覆盖 sfConfig 设置
我的问题如下,我想测试一些依赖于 sfConfig 中特定设置的功能。 建议设置为 app_foo
,默认值为 false
。
测试的“标准”方法是这样的:
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/path_to/index')->
...
end();
但是改变设置是行不通的
sfConfig::set('app_foo', true);
$browser = new sfTestFunctional(new sfBrowser());
My Problem is the following i wanted to test some functionality that depended on a certain setting in the sfConfig.
Proposed the setting is app_foo
and its default is false
.
The "standard" way to test is like:
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/path_to/index')->
...
end();
BUT it does not work to change the setting like
sfConfig::set('app_foo', true);
$browser = new sfTestFunctional(new sfBrowser());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
sfConfig 在测试中无法被覆盖,因为 sfConfig 会在下一个请求时重置。
但是浏览器实例中名为“rawConfiguration”的字段将添加到请求的 sfConfig 中。所以解决方案是设置这个数组:
然后操作知道
sfConfig::get('app_foo')
的值为 true。The sfConfig cannot be overwritten in the test because the sfConfig is reset on the next request.
BUT a field named 'rawConfiguration' in the browser instance is added to the sfConfig for the request. So the solution is to set this array:
Then the action knows the
sfConfig::get('app_foo')
with the value true.samura 的答案很好,您还必须知道配置文件是环境感知的,因此您可以在 app.yml 中执行此操作:
这也适用于 database.yml 文件,允许您在另一个数据库中运行功能测试
The samura answer is nice, you also have to know that config files are environement aware so you can do that in your app.yml:
This is also working on the database.yml file, allowing you to run functionnal tests in another database