# How to replace EventManager of Controller with mock in Test?

**URL:** <https://discourse.laminas.dev/t/how-to-replace-eventmanager-of-controller-with-mock-in-test/2851>\
**Category:** Components & MVC\
**Tags:** laminas-test\
**Created:** [April 16, 2022, 7:26pm UTC](https://discourse.laminas.dev/t/how-to-replace-eventmanager-of-controller-with-mock-in-test/2851 "2022-04-16T19:26:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rarog](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/rarog/32/1291_2.png) [@rarog](https://discourse.laminas.dev/u/rarog)\
**Post date:** [April 16, 2022, 7:26pm UTC](https://discourse.laminas.dev/t/how-to-replace-eventmanager-of-controller-with-mock-in-test/2851/1 "2022-04-16T19:26:13Z")

</div>

So far it looks to me that the event manager is created on the fly and a call to getControllerFullClass() to retrieve the class object would be too late as by this time the event has already be fired.

---

<div class="post-metadata">

**Author:** ![rarog](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/rarog/32/1291_2.png) [@rarog](https://discourse.laminas.dev/u/rarog)\
**Post date:** [April 17, 2022, 12:25pm UTC](https://discourse.laminas.dev/t/how-to-replace-eventmanager-of-controller-with-mock-in-test/2851/2 "2022-04-17T12:25:53Z")

</div>

Okay, I think I just didn’t think far enough. After I set up all the mocks in configureServiceManager I can just retrieve my controller and set the event Manager with my mock of it. As the controller is also a shared service by default, it will be cached and during -\>run() the same instance will be used.
