You are here

public function ContainerAwareEventDispatcherTest::testDispatch 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::testDispatch()
  2. 9 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatch()

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testDispatch() {
  $this->dispatcher
    ->addListener('pre.foo', [
    $this->listener,
    'preFoo',
  ]);
  $this->dispatcher
    ->addListener('post.foo', [
    $this->listener,
    'postFoo',
  ]);
  $this->dispatcher
    ->dispatch(new Event(), self::PREFOO);
  $this
    ->assertTrue($this->listener->preFooInvoked);
  $this
    ->assertFalse($this->listener->postFooInvoked);
  $this
    ->assertInstanceOf(Event::class, $this->dispatcher
    ->dispatch(new Event(), 'noevent'));
  $this
    ->assertInstanceOf(Event::class, $this->dispatcher
    ->dispatch(new Event(), self::PREFOO));
  $event = new Event();
  $return = $this->dispatcher
    ->dispatch($event, self::PREFOO);
  $this
    ->assertSame($event, $return);
}