在测试中,有没有一种方法可以临时覆盖扩展StaticObject的类中Environment::get()返回的内容
我正在为锂离子电池写一个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破解一些东西,但是有没有更纯的锂来实现这一点呢?
发布于 2012-11-19 20:45:25
如果您正在编写测试,那么mocks将是正确的方法,或者是用于返回环境状态的可注入闭包。
https://stackoverflow.com/questions/13445821
复制相似问题