public function testNotifyUntil() { $listener = new Listener(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $e = $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo')); $this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); $this->assertEquals($event, $e, '->notifyUntil() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $e = $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo')); $this->assertEquals('listenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); }
$dispatcher->notify(new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBislistenToFoo', '->notify() notifies all registered listeners in order'); // ->notifyUntil() $t->diag('->notifyUntil()'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $e = $dispatcher->notifyUntil($event = new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFoolistenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); $t->is($e, $event, '->notifyUntil() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $e = $dispatcher->notifyUntil($event = new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); // ->filter() $t->diag('->filter()'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFoo')); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $e = $dispatcher->filter($event = new Event(new stdClass(), 'foo'), 'foo'); $t->is($e->getReturnValue(), '-*foo*-', '->filter() filters a value'); $t->is($e, $event, '->filter() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $dispatcher->connect('foo', array($listener, 'filterFoo')); $e = $dispatcher->filter($event = new Event(new stdClass(), 'foo'), 'foo');