function ContainerAwareEventDispatcherTest::testGetListenersSortsByPriority

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testGetListenersSortsByPriority() {
    $listener1 = new TestEventListener();
    $listener2 = new TestEventListener();
    $listener3 = new TestEventListener();
    $listener1->name = '1';
    $listener2->name = '2';
    $listener3->name = '3';
    $this->dispatcher
        ->addListener('pre.foo', [
        $listener1,
        'preFoo',
    ], -10);
    $this->dispatcher
        ->addListener('pre.foo', [
        $listener2,
        'preFoo',
    ], 10);
    $this->dispatcher
        ->addListener('pre.foo', [
        $listener3,
        'preFoo',
    ]);
    $expected = [
        [
            $listener2,
            'preFoo',
        ],
        [
            $listener3,
            'preFoo',
        ],
        [
            $listener1,
            'preFoo',
        ],
    ];
    $this->assertSame($expected, $this->dispatcher
        ->getListeners('pre.foo'));
}

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