1
votes

phpunit - zend framework

what's the best way to mock / how to test this code $this->getRequest()->getParam('controller') in a controller action helper?

(or any param or that matter as it's all related)

I'm guessing I need to mock the request object and put an expectation on it that method getParam will be found at least once with value controller.

Can someone show me kind of a code example or let me know the best way to do this? thanks!

1
Those zf classes have already been unit tested. Trying to do it again is a pain. I found unit testing controllers too much trouble, so I moved all the logic I could into my models and stopped doing it. Improved my code immensely and made unit testing a breeze. - vascowhite
as part of the method i'm testing, information is set using this so I will not receive code coverage without demonstrating that this can be successfully set in the action helper. I am expected to maintain 100% code coverage. - jsteinmann
That's a bit short sighted, this is probably the best place to start framework.zend.com/manual/en/zend.test.introduction.html, however I would stick by my original recommendation. - vascowhite

1 Answers

1
votes

If you mean how to test your controller with certain params - you can do

$this->request->setParam($paramName, $paramValue);