function ContainerAwareEventDispatcherTest::testStopEventPropagation

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testStopEventPropagation()
  2. 10 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 311

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testStopEventPropagation() {
    $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(self::POSTFOO);
    $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.