public function ContainerAwareEventDispatcherTest::testDispatchLazyListener in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatchLazyListener()
- 9 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatchLazyListener()
File
- core/
tests/ Drupal/ Tests/ Component/ EventDispatcher/ ContainerAwareEventDispatcherTest.php, line 485
Class
- ContainerAwareEventDispatcherTest
- Unit tests for the ContainerAwareEventDispatcher.
Namespace
Drupal\Tests\Component\EventDispatcherCode
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);
}