public function EventDispatcherTest::testDispatch

File

drupal/core/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php, line 106

Class

EventDispatcherTest

Namespace

Symfony\Component\EventDispatcher\Tests

Code

public function testDispatch() {
  $this->dispatcher
    ->addListener('pre.foo', array(
    $this->listener,
    'preFoo',
  ));
  $this->dispatcher
    ->addListener('post.foo', array(
    $this->listener,
    'postFoo',
  ));
  $this->dispatcher
    ->dispatch(self::preFoo);
  $this
    ->assertTrue($this->listener->preFooInvoked);
  $this
    ->assertFalse($this->listener->postFooInvoked);
  $this
    ->assertInstanceOf('Symfony\\Component\\EventDispatcher\\Event', $this->dispatcher
    ->dispatch('noevent'));
  $this
    ->assertInstanceOf('Symfony\\Component\\EventDispatcher\\Event', $this->dispatcher
    ->dispatch(self::preFoo));
  $event = new Event();
  $return = $this->dispatcher
    ->dispatch(self::preFoo, $event);
  $this
    ->assertEquals('pre.foo', $event
    ->getName());
  $this
    ->assertSame($event, $return);
}