コード例 #1
0
 /**
  * Test the removeListener method.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testRemoveListeners()
 {
     // Add 3 listeners listening to the same events.
     $listener1 = new SomethingListener();
     $listener2 = new SomethingListener();
     $listener3 = new SomethingListener();
     $this->instance->addListener('onBeforeSomething', [$listener1, 'onBeforeSomething'])->addListener('onBeforeSomething', [$listener2, 'onBeforeSomething'])->addListener('onBeforeSomething', [$listener3, 'onBeforeSomething']);
     // Remove the listener from a specific event.
     $this->instance->removeListener('onBeforeSomething', [$listener1, 'onBeforeSomething']);
     $this->assertFalse($this->instance->hasListener([$listener1, 'onBeforeSomething']));
     $this->assertTrue($this->instance->hasListener([$listener2, 'onBeforeSomething']));
     $this->assertTrue($this->instance->hasListener([$listener3, 'onBeforeSomething']));
 }
コード例 #2
0
 /**
  * Test the removeListener method.
  *
  * @return  void
  *
  * @covers  Joomla\Event\Dispatcher::removeListener
  * @since   1.0
  */
 public function testRemoveListeners()
 {
     $listener = new SomethingListener();
     $this->instance->addListener($listener);
     // Remove the listener from all events.
     $this->instance->removeListener($listener);
     $this->assertFalse($this->instance->hasListener($listener, 'onBeforeSomething'));
     $this->assertFalse($this->instance->hasListener($listener, 'onSomething'));
     $this->assertFalse($this->instance->hasListener($listener, 'onAfterSomething'));
     $this->instance->addListener($listener);
     // Remove the listener from a specific event.
     $this->instance->removeListener($listener, 'onBeforeSomething');
     $this->assertFalse($this->instance->hasListener($listener, 'onBeforeSomething'));
     $this->assertTrue($this->instance->hasListener($listener, 'onSomething'));
     $this->assertTrue($this->instance->hasListener($listener, 'onAfterSomething'));
     // Remove the listener from a specific event by passing an event object.
     $this->instance->removeListener($listener, new Event('onSomething'));
     $this->assertFalse($this->instance->hasListener($listener, 'onSomething'));
     $this->assertTrue($this->instance->hasListener($listener, 'onAfterSomething'));
 }