You'd simply verify that the listener aggregate is attached correctly:
$evm = $this->getMock('Zend\EventManager\EventManagerInterface');
$evm->expects($this->once())->method('attach')->with($this->isCallback());
$listener = new YourListener();
$listener->attach($evm);
And then that callbacks work:
$listener = new YourListener();
$listener->attach($evm);
$bar = $listener->someCallbackMethod($event); // $event should be an event
interface instance
// assert stuff here
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On 22 October 2013 20:34, Norbert Máté <[email protected]> wrote:
> Ok. I wanted to test a logger module. In the Module.php I have set up a
> shared event listener and I wanted to test that if I somewhere will trigger
> a 'log' event this module will catch it. Maybe it is silliness to test
> this?
>
>
> On 22 October 2013 21:18, Julian Vidal <[email protected]> wrote:
>
> > Artur,
> >
> > > Julian: If you just care if any event is fired at all, use the Mock
> that
> > Marco suggested.
> >
> > You mean Norbert :)
> >
> >
> > On Tue, Oct 22, 2013 at 2:08 PM, Artur Bodera <[email protected]> wrote:
> >
> > >
> > > On Tue, Oct 22, 2013 at 8:06 PM, Artur Bodera <[email protected]>
> wrote:
> > >
> > >> If you want to test if specific event has been triggered, then you'd
> > need
> > >> to use a closure as I've previously suggested. That is because
> > ::trigger()
> > >> method can be called in 4 different styles<
> >
> https://github.com/zendframework/zf2/blob/master/library/Zend/EventManager/EventManagerInterface.php#L20-L37
> > >
> > >> ,
> > >
> > >
> > > Clarification: unless of course you know _exactly_ how your component
> is
> > > calling trigger() method on EM. In such case you can use ->with() tests
> > of PHPUnit
> > > stubs<
> > http://phpunit.de/manual/current/en/test-doubles.html#test-doubles.stubs
> >
> > > .
> > >
> > >
> > >
> > > --
> > > [email protected]
> > > +48 695 600 936
> > > http://thinkscape.pro
> > >
> >
>