PHPUnit and HTTP test

I am being pedantic but…

I am implementing unit test for a framework and the one component I cannot figure out how to test is the Request object, primarily because it is a simple wrapper around the $_REQUEST super global. I need to either fake HTTP request to properly populate this variable (at least PHP 5.3.4) or I need to remove the dependency and initialize the request object using $_REQUEST or whatever I wish.

While this seems the logical solution (I am always in favour of DI/IoC) I dislike the solution in this case, for reasons I do not wish to get into right now, or I fear this discussion taking on a whole different purpose.

What I want to know, is there a work around in PHPUnit (perhaps using the now built-in HTTP server of PHP 5.4.0 binary?) to allow me to test my framework at the Request object level without changing the interface/implementation of my request object (ie: injecting $_REQUEST)?

Currently the Request simply acts as a simple wrapper around the $_REQUEST super global - and it does not seem possible to populate super globals manually within the test itself.

Remember - I am not looking to change the code at all in my Request object so using globals, etc is not the solution I seek. Rather a PHPUnit extension or technique that allows me to invoke the tests in an HTTP context as opposed to CLI.

Regards,
Alex

FWIW, it really sounds like you should be injecting a mock $_REQUEST array into the Request object; after all, that’s what you’re testing no?

Have you thought about using a PHP based HTTP client such as Guzzle or [URL=“https://github.com/kriswallsmith/Buzz”]Buzz and emulating a HTTP request with that?

FWIW, it really sounds like you should be injecting a mock $_REQUEST array into the Request object; after all, that’s what you’re testing no?

I really want to avoid that, I’ve tried that approach, and while it circumvents my testing issue, it introduces other problems. Thats a whole different discussion though. :slight_smile:

Buzz looks interesting, but I am not sure it’s what I am looking for. An HTTP server is what I require, I think anyway. :stuck_out_tongue:

Basically my unit tests are executed under the context of CLI environment - as per usual. This works 99% of the time, except when testing my controllers, because they rely on the request object having all required HTTP details. There might be a few instances where views depend on request objects as well, not 100% certain though.

EDIT | Seems like the only way to test controllers without a mock request object is to use Selenium/PHPUnit or switch over to SimpleTest which seems to support web testing.