function ContainerAwareEventDispatcherTest::testAddListener

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testAddListener()
  2. 8.9.x core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testAddListener()

File

core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php, line 274

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testAddListener() {
  $this->dispatcher
    ->addListener('pre.foo', [
    $this->listener,
    'preFoo',
  ]);
  $this->dispatcher
    ->addListener('post.foo', [
    $this->listener,
    'postFoo',
  ]);
  $this->assertTrue($this->dispatcher
    ->hasListeners());
  $this->assertTrue($this->dispatcher
    ->hasListeners(self::PREFOO));
  $this->assertTrue($this->dispatcher
    ->hasListeners(self::POSTFOO));
  $this->assertCount(1, $this->dispatcher
    ->getListeners(self::PREFOO));
  $this->assertCount(1, $this->dispatcher
    ->getListeners(self::POSTFOO));
  $this->assertCount(2, $this->dispatcher
    ->getListeners());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.