You are here

public function ContainerAwareEventDispatcherTest::testAddSubscriberWithPriorities in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testAddSubscriberWithPriorities()

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testAddSubscriberWithPriorities() {
  $eventSubscriber = new TestEventSubscriber();
  $this->dispatcher
    ->addSubscriber($eventSubscriber);
  $eventSubscriber = new TestEventSubscriberWithPriorities();
  $this->dispatcher
    ->addSubscriber($eventSubscriber);
  $listeners = $this->dispatcher
    ->getListeners('pre.foo');
  $this
    ->assertTrue($this->dispatcher
    ->hasListeners(self::PREFOO));
  $this
    ->assertCount(2, $listeners);
  $this
    ->assertInstanceOf(TestEventSubscriberWithPriorities::class, $listeners[0][0]);
}