Zend framework2 如何测试$服务器[';远程地址';]

Zend framework2 如何测试$服务器[';远程地址';],zend-framework2,phpunit,Zend Framework2,Phpunit,我正在运行Zf2,在我的控制器中有一条线路 $apiCaller = $_SERVER['REMOTE_ADDR']; 当我运行phpunit3.7.27时,它抛出以下错误 There was 1 error: 1) MainTest\Controller\myControllerTest::testcreateActionCanBeAccessed Undefined index: REMOTE_ADDR /home/websites/mysite/module/Main/src/Mai

我正在运行Zf2,在我的控制器中有一条线路

$apiCaller = $_SERVER['REMOTE_ADDR'];
当我运行phpunit3.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');

也许这会有帮助:您使用的是phing还是jenkins?您不应该在代码中访问$\u服务器或任何其他超级全局。相反,您应该使用request对象作为单元测试的所有注入点。