public function ContainerAwareEventDispatcherTest::testDispatchWithServices in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatchWithServices()
- 9 core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::testDispatchWithServices()
File
- core/
tests/ Drupal/ Tests/ Component/ EventDispatcher/ ContainerAwareEventDispatcherTest.php, line 157
Class
- ContainerAwareEventDispatcherTest
- Unit tests for the ContainerAwareEventDispatcher.
Namespace
Drupal\Tests\Component\EventDispatcherCode
public function testDispatchWithServices() {
$container = new ContainerBuilder();
$container
->register('listener_service', TestEventListener::class);
$listeners = [
'test_event' => [
0 => [
[
'service' => [
'listener_service',
'preFoo',
],
],
],
],
];
$dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
$dispatcher
->dispatch(new Event(), 'test_event');
$listenerService = $container
->get('listener_service');
$this
->assertTrue($listenerService->preFooInvoked);
}