Zend Framework 调用未定义的方法 Zend\Http\Request::getServer()

Zend Framework Call to undefined method Zend\Http\Request::getServer()

我有一个控制器,当请求为 Post 时,它会收到请求,然后我会从那里收到 REMOTE_ADDR 和 REQUEST_TIME。代码工作正常,我得到了我需要的信息。

但是,我正在为我的 Web 应用程序的整个流程编写集成测试,当我发送请求时,我收到 Call to undefined method Zend\Http\Request::getServer() 时我在控制器中的操作点。

$server = $this->getRequest()->getServer();
$remoteAddr = $server['REMOTE_ADDR'];
$timestamp = $server['REQUEST_TIME'];

当我做的时候

$request = $this->getRequest();

看看$request,它有方法、uri、queryParams、postParams、fileParams、版本、headers、元数据和内容。 postData 包含我通过测试发送的所有内容,但是当它到达获取服务器的位置时它崩溃了。

有什么想法吗?

谢谢。

您的应用程序正在使用的请求 class 是 Zend\Http\PhpEnvironment\Request,它将 Zend\Http\Request 扩展为一些 PHP 特定的内容,例如 getServer()。更改您的测试以使用它,它应该可以正常工作。