As Marco wrote, you generally don't want to test event listeners
within your Module, because that would need much more mocking.

To make listener testing easier, you want to have them in concrete
instances of AbstractListenerAggregate or implementations of
ListenerAggregateInterface using ListenerAggregateTrait, so you can
actually test them as individual units.

I can link an example of a listener class [1] and its unit test [2],
but please bear in mind that much of that code is largely inspired by
the work of other members of the zf2 community, so all credit goes to
them. That means you can find much better examples elsewhere on
Github. (i.e. Doctrine modules testing suites are the ones I've read,
I suggest you check them out [3][4]).

If you then want to go further, you can functionally test the whole
Module class to make sure it has a legit configuration, registers all
the services needed and attaches the listener to the EventManager
during the MVC bootstrap event. That involves building an actual
ServiceManager instance with a test application configuration and
manually triggering the module loading via the actual ModuleManager
service. Nevertheless, this should come after you have a pretty much
complete unit test suite, since it would involve a lot of dependencies
that are assumed to be already tested, so they are given to actually
work.

Cheers.

Stefano Torresi

[1] 
https://github.com/stefanotorresi/MyI18n/blob/feature/MyBackend-support/src/MyI18n/Listener/MissingTranslation.php
[2] 
https://github.com/stefanotorresi/MyI18n/blob/feature/MyBackend-support/tests/MyI18nTest/Listener/MissingTranslationTest.php
[3] https://github.com/doctrine/DoctrineModule/tree/master/tests
[4] https://github.com/doctrine/DoctrineORMModule/tree/master/tests

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to