Testing Zend Framework 2 code which uses a HTTP Request object.

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 little bit of hunting around I came up with the following simple solution:

My PHPUnit boostrap file for reference

Leave a Reply

Your email address will not be published. Required fields are marked *