function ContainerAwareEventDispatcherTest::testGetAllListenersSortsByPriority

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testGetAllListenersSortsByPriority() {
    $listener1 = new TestEventListener();
    $listener2 = new TestEventListener();
    $listener3 = new TestEventListener();
    $listener4 = new TestEventListener();
    $listener5 = new TestEventListener();
    $listener6 = new TestEventListener();
    $this->dispatcher
        ->addListener('pre.foo', $listener1, -10);
    $this->dispatcher
        ->addListener('pre.foo', $listener2);
    $this->dispatcher
        ->addListener('pre.foo', $listener3, 10);
    $this->dispatcher
        ->addListener('post.foo', $listener4, -10);
    $this->dispatcher
        ->addListener('post.foo', $listener5);
    $this->dispatcher
        ->addListener('post.foo', $listener6, 10);
    $expected = [
        'pre.foo' => [
            $listener3,
            $listener2,
            $listener1,
        ],
        'post.foo' => [
            $listener6,
            $listener5,
            $listener4,
        ],
    ];
    $this->assertSame($expected, $this->dispatcher
        ->getListeners());
}

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