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:
Continue reading

Should you test private methods?

While trying to learn TDD I found myself asking this question fairly often. I’ve searched for the answer online many times and always got mixed responses. I have also devised many clever ways to try and test them and even ways to mock $this. However now I’ve got to a point where I’m confident I have a very valid answer to this question and I’m going to try to explain it here… Continue reading