public function test_that_has_handlers_returns_true_with_handlers_added_in_memory() { $dispatcher = new ServiceAwareEventDispatcher($this->container); $type = ClassName::underscore(UserRegisteredEvent::class); $dispatcher->addHandler($type, function () { }); $this->assertTrue($dispatcher->hasHandlers($type)); }
<?php use Novuso\Common\Application\Messaging\Event\ServiceAwareEventDispatcher; use Novuso\Common\Application\Service\ServiceContainer; use Novuso\Test\Common\Resources\Domain\Messaging\Event\UserRegisteredSubscriber; $container = new ServiceContainer(); $container->set('event.dispatcher', function ($container) { $dispatcher = new ServiceAwareEventDispatcher($container); $dispatcher->registerService(UserRegisteredSubscriber::class, 'subscriber.user_registered'); return $dispatcher; }); $container->set('subscriber.user_registered', function () { return new UserRegisteredSubscriber(); }); return $container;