我使用Yii2和Codeception来运行测试。
当我运行功能测试时,没有定义$SERVER['REMOTE_ADDR']
。我如何模拟在这些测试中使用的ip。
我试过$SERVER['REMOTE_ADDR'] = '127.0.0.1'
,但它不起作用。
在tests / _support下创建功能性Helper类(如果它不存在):
class FunctionalHelper extends \Codeception\Module {
public function _before(\Codeception\TestInterface $test)
{
$this->getModule('Yii2')->client->defaultServerVars = array_merge(
$this->getModule('Yii2')->client->defaultServerVars,
['REMOTE_ADDR' => '127.0.0.1']
);
}
}