function ContainerAwareEventDispatcherTest::testStopEventPropagation
File
-
core/
tests/ Drupal/ Tests/ Component/ EventDispatcher/ ContainerAwareEventDispatcherTest.php, line 335
Class
- ContainerAwareEventDispatcherTest
- Unit tests for the ContainerAwareEventDispatcher.
Namespace
Drupal\Tests\Component\EventDispatcherCode
public function testStopEventPropagation() : void {
$otherListener = new TestEventListener();
// postFoo() stops the propagation, so only one listener should
// be executed
// Manually set priority to enforce $this->listener to be called first
$this->dispatcher
->addListener('post.foo', [
$this->listener,
'postFoo',
], 10);
$this->dispatcher
->addListener('post.foo', [
$otherListener,
'postFoo',
]);
$this->dispatcher
->dispatch(new Event(), self::POST_FOO);
$this->assertTrue($this->listener->postFooInvoked);
$this->assertFalse($otherListener->postFooInvoked);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.