public function EventDispatcherTest::testDispatchByPriority

File

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

Class

EventDispatcherTest

Namespace

Symfony\Component\EventDispatcher\Tests

Code

public function testDispatchByPriority() {
  $invoked = array();
  $listener1 = function () use (&$invoked) {
    $invoked[] = '1';
  };
  $listener2 = function () use (&$invoked) {
    $invoked[] = '2';
  };
  $listener3 = function () use (&$invoked) {
    $invoked[] = '3';
  };
  $this->dispatcher
    ->addListener('pre.foo', $listener1, -10);
  $this->dispatcher
    ->addListener('pre.foo', $listener2);
  $this->dispatcher
    ->addListener('pre.foo', $listener3, 10);
  $this->dispatcher
    ->dispatch(self::preFoo);
  $this
    ->assertEquals(array(
    '3',
    '2',
    '1',
  ), $invoked);
}