function ContainerAwareEventDispatcherTest::testDispatchLazyListener

File

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

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.