function ContainerAwareEventDispatcherTest::testDispatch

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

File

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

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.