function ContainerAwareEventDispatcherTest::testDispatch

Same name in other branches
  1. 9 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 287

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(self::PREFOO);
    $this->assertTrue($this->listener->preFooInvoked);
    $this->assertFalse($this->listener->postFooInvoked);
    $this->assertInstanceOf(Event::class, $this->dispatcher
        ->dispatch('noevent'));
    $this->assertInstanceOf(Event::class, $this->dispatcher
        ->dispatch(self::PREFOO));
    $event = new Event();
    $return = $this->dispatcher
        ->dispatch(self::PREFOO, $event);
    $this->assertSame($event, $return);
}

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