Testing Zend Framework 2 Code Which Uses a HTTP Request object
26 October 2013
WARNING: This post was written a long time ago. It exists here as a record
and may not reflect my current views or opinions. Also, any code,
technologies or examples may be out of date.
Yesterday, I was trying to test that the ServiceManager was correctly creating
an instance of a class which took a Zend\Http\Request object as a
parameter to the constructor. The problem I ran into was that since the Zend
MVC Application had been initialised from PHPUnit, it decided it was running in
a console context and was using a Zend\Console\Request instead.
After a bit of hunting around I came up with the following, simple
solution: