On Sat, Oct 5, 2013 at 7:08 PM, Marco Pivetta <[email protected]> wrote:
> Also wrong =D
>
>
Julian: If you just care if any event is fired at all, use the Mock that
Marco suggested.
Minimal, theoretical example would be something like this:
$em = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$em->expects($this->atLeastOnce())->method('trigger'));
$someComponentUsingEm->setEventManager($em);
This test above will fail unless something has been triggered at least once.
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>,
and PHPUnit does not support this kind of argument resolution. Inside a
closure you can introspect the event object and check its properties.
Alternatively, you can also use self-shunting
subclass<http://phpunit.de/manual/3.0/en/mock-objects.html>
.
--
[email protected]
+48 695 600 936
http://thinkscape.pro