function ContainerAwareEventDispatcherTest::testDispatchLazyListener

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testDispatchLazyListener() {
    $called = 0;
    $factory = function () use (&$called) {
        ++$called;
        return new TestWithDispatcher();
    };
    $this->dispatcher
        ->addListener('foo', [
        $factory,
        'foo',
    ]);
    $this->assertSame(0, $called);
    $this->dispatcher
        ->dispatch(new Event(), 'foo');
    $this->dispatcher
        ->dispatch(new Event(), 'foo');
    $this->assertSame(1, $called);
}

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