function ContainerAwareEventDispatcherTest::testGetListenersWithCallables

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testGetListenersWithCallables() {
    // When passing in callables exclusively as listeners into the event
    // dispatcher constructor, the event dispatcher must not attempt to
    // resolve any services.
    $container = $this->getMockBuilder(ContainerInterface::class)
        ->getMock();
    $container->expects($this->never())
        ->method($this->anything());
    $firstListener = new CallableClass();
    $secondListener = function () {
    };
    $thirdListener = [
        new TestEventListener(),
        'preFoo',
    ];
    $listeners = [
        'test_event' => [
            0 => [
                [
                    'callable' => $firstListener,
                ],
                [
                    'callable' => $secondListener,
                ],
                [
                    'callable' => $thirdListener,
                ],
            ],
        ],
    ];
    $dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
    $actualListeners = $dispatcher->getListeners();
    $expectedListeners = [
        'test_event' => [
            $firstListener,
            $secondListener,
            $thirdListener,
        ],
    ];
    $this->assertSame($expectedListeners, $actualListeners);
}

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