Codeception功能测试的假IP

问题描述 投票:1回答:1

我使用Yii2和Codeception来运行测试。

当我运行功能测试时,没有定义$SERVER['REMOTE_ADDR']。我如何模拟在这些测试中使用的ip。

我试过$SERVER['REMOTE_ADDR'] = '127.0.0.1',但它不起作用。

yii2 codeception
1个回答
0
投票

在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']
        );            
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.