You are here

public function ContainerAwareEventDispatcherTest::testDispatch in Drupal 8

Same name and namespace 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()

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