You are here

public function ContainerAwareEventDispatcherTest::testRemoveService in Zircon Profile 8

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

File

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

Class

ContainerAwareEventDispatcherTest
Unit tests for the ContainerAwareEventDispatcher.

Namespace

Drupal\Tests\Component\EventDispatcher

Code

public function testRemoveService() {
  $container = new ContainerBuilder();
  $container
    ->register('listener_service', 'Symfony\\Component\\EventDispatcher\\Tests\\TestEventListener');
  $container
    ->register('other_listener_service', 'Symfony\\Component\\EventDispatcher\\Tests\\TestEventListener');
  $listeners = array(
    'test_event' => array(
      0 => array(
        array(
          'service' => array(
            'listener_service',
            'preFoo',
          ),
        ),
        array(
          'service' => array(
            'other_listener_service',
            'preFoo',
          ),
        ),
      ),
    ),
  );
  $dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
  $listenerService = $container
    ->get('listener_service');
  $dispatcher
    ->removeListener('test_event', array(
    $listenerService,
    'preFoo',
  ));

  // Ensure that other service was not initialized during removal of the
  // listener service.
  $this
    ->assertFalse($container
    ->initialized('other_listener_service'));
  $dispatcher
    ->dispatch('test_event');
  $this
    ->assertFalse($listenerService->preFooInvoked);
  $otherService = $container
    ->get('other_listener_service');
  $this
    ->assertTrue($otherService->preFooInvoked);
}