Exemplo n.º 1
0
 /**
  * @return DomainEventPublisher
  */
 private static function instance()
 {
     if (static::$instance === null) {
         static::$instance = new static();
         static::$instance->setEventBus(EventBus::create());
     }
     return static::$instance;
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 /**
  * @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);
 }
Exemplo n.º 4
0
 /**
  * Test eventBus method.
  */
 public function testEventBus()
 {
     $this->given($eventBus = EventBus::create())->when(DomainEventPublisher::set($eventBus))->then()->object(DomainEventPublisher::eventBus())->isEqualTo($eventBus);
 }