function ContainerAwareEventDispatcherTest::testStopEventPropagation

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

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.