You are here

public function ContainerAwareEventDispatcherTest::testStopEventPropagation in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testStopEventPropagation()
  2. 9 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testStopEventPropagation()

File

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

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(new Event(), self::POSTFOO);
  $this
    ->assertTrue($this->listener->postFooInvoked);
  $this
    ->assertFalse($otherListener->postFooInvoked);
}