/**
  * Test the getListeners method.
  *
  * @return  void
  *
  * @covers  Joomla\Event\Dispatcher::getListeners
  * @since   1.0
  */
 public function testGetListeners()
 {
     $this->assertEmpty($this->instance->getListeners('onSomething'));
     $listener1 = new SomethingListener();
     $listener2 = new SomethingListener();
     $listener3 = new SomethingListener();
     $this->instance->addListener($listener1)->addListener($listener2)->addListener($listener3);
     $onBeforeSomethingListeners = $this->instance->getListeners('onBeforeSomething');
     $this->assertSame($listener1, $onBeforeSomethingListeners[0]);
     $this->assertSame($listener2, $onBeforeSomethingListeners[1]);
     $this->assertSame($listener3, $onBeforeSomethingListeners[2]);
     $onSomethingListeners = $this->instance->getListeners(new Event('onSomething'));
     $this->assertSame($listener1, $onSomethingListeners[0]);
     $this->assertSame($listener2, $onSomethingListeners[1]);
     $this->assertSame($listener3, $onSomethingListeners[2]);
     $onAfterSomethingListeners = $this->instance->getListeners('onAfterSomething');
     $this->assertSame($listener1, $onAfterSomethingListeners[0]);
     $this->assertSame($listener2, $onAfterSomethingListeners[1]);
     $this->assertSame($listener3, $onAfterSomethingListeners[2]);
 }
Пример #2
0
 /**
  * Test the getListeners method.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetListeners()
 {
     $this->assertEmpty($this->instance->getListeners('onSomething'));
     // Add 3 listeners listening to the same events.
     $listener1 = new SomethingListener();
     $listener2 = new SomethingListener();
     $listener3 = new SomethingListener();
     $this->instance->addListener('onBeforeSomething', [$listener1, 'onBeforeSomething'])->addListener('onSomething', [$listener1, 'onSomething'])->addListener('onAfterSomething', [$listener1, 'onAfterSomething'])->addListener('onBeforeSomething', [$listener2, 'onBeforeSomething'])->addListener('onSomething', [$listener2, 'onSomething'])->addListener('onAfterSomething', [$listener2, 'onAfterSomething'])->addListener('onBeforeSomething', [$listener3, 'onBeforeSomething'])->addListener('onSomething', [$listener3, 'onSomething'])->addListener('onAfterSomething', [$listener3, 'onAfterSomething']);
     $onBeforeSomethingListeners = $this->instance->getListeners('onBeforeSomething');
     $this->assertSame([$listener1, 'onBeforeSomething'], $onBeforeSomethingListeners[0]);
     $this->assertSame([$listener2, 'onBeforeSomething'], $onBeforeSomethingListeners[1]);
     $this->assertSame([$listener3, 'onBeforeSomething'], $onBeforeSomethingListeners[2]);
     $onSomethingListeners = $this->instance->getListeners('onSomething');
     $this->assertSame([$listener1, 'onSomething'], $onSomethingListeners[0]);
     $this->assertSame([$listener2, 'onSomething'], $onSomethingListeners[1]);
     $this->assertSame([$listener3, 'onSomething'], $onSomethingListeners[2]);
     $onAfterSomethingListeners = $this->instance->getListeners('onAfterSomething');
     $this->assertSame([$listener1, 'onAfterSomething'], $onAfterSomethingListeners[0]);
     $this->assertSame([$listener2, 'onAfterSomething'], $onAfterSomethingListeners[1]);
     $this->assertSame([$listener3, 'onAfterSomething'], $onAfterSomethingListeners[2]);
 }