/** * @return DomainEventPublisher */ private static function instance() { if (static::$instance === null) { static::$instance = new static(); static::$instance->setEventBus(EventBus::create()); } return static::$instance; }
/** * Test RemoveSubscriber method. */ public function testRemoveSubscriber() { $this->given($eventBus = EventBus::create())->and($subscriber = new UserEventSubscriber())->and($eventBus->addSubscriber($subscriber))->then()->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))->isTrue()->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))->isTrue()->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))->isTrue()->and()->when($eventBus->removeSubscriber($subscriber))->then()->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))->isFalse()->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))->isFalse()->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))->isFalse(); }
/** * @param callable|ApplicationConfig $config * * @return ConsoleApplication */ protected function createApplication($config) { $commandBus = CommandBus::create(); $eventBus = EventBus::create(); $postService = new PostService($eventBus); $commandBus->addHandler(CreateBlogCommand::class, new BlogService($eventBus)); $commandBus->addHandler(CreatePostCommand::class, $postService); $commandBus->addHandler(ChangePostTitleCommand::class, $postService); return new ConsoleApplication($config, $commandBus, $eventBus); }
/** * Test eventBus method. */ public function testEventBus() { $this->given($eventBus = EventBus::create())->when(DomainEventPublisher::set($eventBus))->then()->object(DomainEventPublisher::eventBus())->isEqualTo($eventBus); }