/** * Issue #2 - Higher priority handles don't stop lower priority listeners from seeing event. * * @param MockListener $listener * @param Event $event * * @throws \DomainException * @throws \InvalidArgumentException */ public function it_should_only_call_listeners_for_event_until_one_of_them_handles_the_event(MockListener $listener, Event $event) { $event->hasBeenHandled()->willReturn(true)->shouldBeCalled(); $listener->method2($event, 'test1', $this)->willReturn($event); $this->addListener('test1', [$listener, 'method2']); $this->addListener('test1', [$listener, 'method1'], 'last'); $this->getListeners()->shouldHaveKey('test1'); $expected = [0 => [[$listener, 'method2']], -1 => [[$listener, 'method1']]]; $this->getListeners('test1')->shouldReturn($expected); $listener->method2($event, 'test1', $this)->shouldBeCalled(); $listener->method1($event, 'test1', $this)->shouldNotBeCalled(); $this->trigger('test1', $event); }
/** * @param MockListener $listener1 * @param MockListener $listener2 * @param Event $event * * @throws \DomainException * @throws \InvalidArgumentException */ public function it_should_only_call_listeners_for_current_events_when_event_triggers(MockListener $listener1, MockListener $listener2, Event $event) { $this->addListener('test1', [$listener1, 'method1']); $this->addListener('test2', [$listener2, 'method2']); $this->getListeners()->shouldHaveKey('test1'); $this->getListeners()->shouldHaveKey('test2'); $event->hasBeenHandled()->willReturn(true); /** @noinspection PhpStrictTypeCheckingInspection */ $listener2->method2($event, Argument::is('test2'), $this)->shouldBeCalled(); /** @noinspection PhpStrictTypeCheckingInspection */ $listener1->method1($event, Argument::any(), $this)->shouldNotHaveBeenCalled(); $this->trigger('test2', $event); }