Example #1
0
 /**
  * @param EventSubscriberInterface $subscriber
  *
  * @return $this
  */
 public function addEventSubscriber(EventSubscriberInterface $subscriber)
 {
     if ($this->eventBus === null) {
         throw new \RuntimeException('The event bus should not be null');
     }
     $this->eventBus->addSubscriber($subscriber);
     return $this;
 }
Example #2
0
 /**
  * @param DomainEventSubscriberInterface $subscriber
  */
 protected function addSubscriber(DomainEventSubscriberInterface $subscriber)
 {
     $this->eventBus->addSubscriber($subscriber);
 }
 /**
  * @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);
 }
Example #4
0
 /**
  * @param ChangePostTitleCommand $command
  */
 public function changePostTitle(ChangePostTitleCommand $command)
 {
     $this->eventBus->dispatch(new PostTitleWasChanged($command->title()));
 }
Example #5
0
 /**
  * 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();
 }
 /**
  * Test eventBus method.
  */
 public function testEventBus()
 {
     $this->given($eventBus = EventBus::create())->when(DomainEventPublisher::set($eventBus))->then()->object(DomainEventPublisher::eventBus())->isEqualTo($eventBus);
 }