1

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!

hakre
  • 193,403
  • 52
  • 435
  • 836
jsteinmann
  • 4,502
  • 3
  • 17
  • 21
  • read this response http://stackoverflow.com/questions/1935541/phpunit-test-mvc-controller-with-post-variable#answer-1935553 – Jimmy Collazos May 06 '12 at 19:34
  • 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 May 06 '12 at 21:02
  • 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 May 06 '12 at 23:00
  • That's a bit short sighted, this is probably the best place to start http://framework.zend.com/manual/en/zend.test.introduction.html, however I would stick by my original recommendation. – vascowhite May 07 '12 at 06:36

1 Answers1

1

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

$this->request->setParam($paramName, $paramValue);
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82