测试Lithium中的环境敏感代码

时间:2012-11-18 23:42:16

标签: unit-testing lithium

在测试中,有没有办法暂时覆盖Environment::get()范围内StaticObject返回的内容?

我正在为Lithium写一个feature toggle插件。我想根据环境测试开关功能。例如,功能new_ui应该在暂存中打开但在生产中关闭。

在我的测试中,我希望能够做到这样的事情:

Features::add('new_ui', array('production' => false, 'staging' => true));
// Magic that makes Environment::get() in the Features class return 'staging'
$this->assertTrue(Feature::check('new_ui'));
// Magic that makes Environment::get() in the Features class return 'production'
$this->assertFalse(Feature::check('new_ui'));

我可能会使用MockEnvironment一起破解某些东西,但是有更纯粹的锂方法来实现这一目标吗?

1 个答案:

答案 0 :(得分:0)

如果您正在编写测试,那么模拟将是正确的方法,或者是用于返回环境状态的注入式闭包。