2

我正在运行 Zf2 并且在我的控制器中有一行

$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

如何对这条线进行单元测试?

4

1 回答 1

2

感谢@Mike B,

将代码行更改为以下

  $servParam = $this->getRequest()->getServer();
  $apiCaller = $servParam->get('REMOTE_ADDR');
于 2013-10-17T17:16:37.667 回答