You are here

public function ContainerAwareEventDispatcherTest::testDispatchWithServices in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatchWithServices()

File

core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php, line 127
Contains \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest.

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testDispatchWithServices() {
  $container = new ContainerBuilder();
  $container
    ->register('listener_service', 'Symfony\\Component\\EventDispatcher\\Tests\\TestEventListener');
  $listeners = array(
    'test_event' => array(
      0 => array(
        array(
          'service' => array(
            'listener_service',
            'preFoo',
          ),
        ),
      ),
    ),
  );
  $dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
  $dispatcher
    ->dispatch('test_event');
  $listenerService = $container
    ->get('listener_service');
  $this
    ->assertTrue($listenerService->preFooInvoked);
}