2

I have a controller, that when request is Post, it gets the request, and from there I get REMOTE_ADDR, and REQUEST_TIME. The code works just fine, I get that information that I need.

However, I am writing an integration test for the entire flow of my web app, and when I send the request, I get Call to undefined method Zend\Http\Request::getServer() when it gets to that point of my action in the controller.

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

When I do

$request = $this->getRequest();

and look at $request, it has method, uri, queryParams, postParams, fileParams, version, headers, metadata and content. postData has everything I'm sending via my test, but it crashes when it gets to the point of getting the server.

Any ideas?

Thank you.

1 Answer 1

4

The request class your application is using is Zend\Http\PhpEnvironment\Request, which extends Zend\Http\Request with some PHP-specific stuff like getServer(). Change your test to use that and it should work fine.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much, that was awesome! wish i could up vote.
actually, quick question...any idea why REMOTE_ADDR might not be available when i get server? it doesn't show up on my test so I can't get the ip address that I need to keep running the test. thanks
You will need to set that. PHP won't populate the REMOTE_ADDR environment variable since it's not a proper request. You can use setServer() to fake it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.