public function ContainerAwareEventDispatcherTest::testHasListenersOnLazyLoad

File

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

Class

ContainerAwareEventDispatcherTest

Namespace

Symfony\Component\EventDispatcher\Tests

Code

public function testHasListenersOnLazyLoad() {
  $event = new Event();
  $service = $this
    ->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service');
  $container = new Container();
  $container
    ->set('service.listener', $service);
  $dispatcher = new ContainerAwareEventDispatcher($container);
  $dispatcher
    ->addListenerService('onEvent', array(
    'service.listener',
    'onEvent',
  ));
  $event
    ->setDispatcher($dispatcher);
  $event
    ->setName('onEvent');
  $service
    ->expects($this
    ->once())
    ->method('onEvent')
    ->with($event);
  $this
    ->assertTrue($dispatcher
    ->hasListeners());
  if ($dispatcher
    ->hasListeners('onEvent')) {
    $dispatcher
      ->dispatch('onEvent');
  }
}