zend-framework2phpunitzfcuserbjyauthorize

How to teste an action on Zend Framework 2 and ZfcUser with zfcUserIdentity Helper


Following this way Unit Testing a Zend Framework 2 application I am work with ZfcUser and try to test some action in my controller. But when the test is executed I get and error because I am using $this->zfcUserIdentity() to get the user name in my view.

How to can I make this test? I think to mock this method, but I don't have idea how to do that.


Solution

  • You can take a look at the ZfcUser tests: https://github.com/ZF-Commons/ZfcUser/blob/master/tests/ZfcUserTest/Controller/UserControllerTest.php#L61-L279

    Basicly you have to mock the ZfcUserIdentity controller plugin and tell the controller plugin manager to use that mock.