我正在运行 Zf2,在我的 Controller 中有一行
$apiCaller = $_SERVER['REMOTE_ADDR'];
当我运行 PHPUnit 3.7.27 时,它抛出以下错误,
There was 1 error:
1) MainTest\Controller\myControllerTest::testcreateActionCanBeAccessed
Undefined index: REMOTE_ADDR
/home/websites/mysite/module/Main/src/Main/Controller/myController.php:113
如何对这条线进行单元测试?
最佳答案
感谢@Mike B,
将代码行更改为以下内容
$servParam = $this->getRequest()->getServer();
$apiCaller = $servParam->get('REMOTE_ADDR');
关于zend-framework2 - 如何 phpunit 测试 $_SERVER ['REMOTE_ADDR' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19432708/