public function test_that_event_is_dispatched_correctly_when_service_is_changed()
 {
     /** @var ServiceAwareEventDispatcher $dispatcher */
     $dispatcher = $this->container->get('event.dispatcher');
     $event = new UserRegisteredEvent('*****@*****.**', 'James', 'Smith', 'D');
     $dispatcher->dispatch($event);
     $this->container->set('subscriber.user_registered', function () {
         return new UserRegisteredSubscriber();
     });
     $subscriber = $this->container->get('subscriber.user_registered');
     $dispatcher->dispatch($event);
     $this->assertTrue($subscriber->isUserRegistered('*****@*****.**'));
 }
Exemplo n.º 2
0
 /**
  * Checks if a handler is defined for a query
  *
  * @param string $queryClass The full query class name
  *
  * @return bool
  */
 public function hasHandler(string $queryClass) : bool
 {
     $type = Type::create($queryClass)->toString();
     if (!isset($this->handlers[$type])) {
         return false;
     }
     $service = $this->handlers[$type];
     return $this->container->has($service);
 }
Exemplo n.º 3
0
 /**
  * Lazy loads event handlers from the service container
  *
  * @param string $eventType The event type
  *
  * @return void
  */
 protected function lazyLoad(string $eventType)
 {
     if (isset($this->serviceIds[$eventType])) {
         foreach ($this->serviceIds[$eventType] as $args) {
             list($serviceId, $method, $priority) = $args;
             $service = $this->container->get($serviceId);
             $key = $serviceId . '.' . $method;
             if (!isset($this->services[$eventType][$key])) {
                 $this->addHandler($eventType, [$service, $method], $priority);
             } elseif ($service !== $this->services[$eventType][$key]) {
                 parent::removeHandler($eventType, [$this->services[$eventType][$key], $method]);
                 $this->addHandler($eventType, [$service, $method], $priority);
             }
             $this->services[$eventType][$key] = $service;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @expectedException \Novuso\System\Exception\LookupException
  */
 public function test_that_query_map_throws_exception_when_handler_is_not_registered()
 {
     $this->container['query.handlers'] = [];
     $queryMap = $this->container->get('query.service_map');
     $queryMap->getHandler(UserByEmailQuery::class);
 }
 /**
  * @expectedException \Novuso\System\Exception\LookupException
  */
 public function test_that_command_map_throws_exception_when_handler_is_not_registered()
 {
     $this->container['command.handlers'] = [];
     $commandMap = $this->container->get('command.service_map');
     $commandMap->getHandler(RegisterUserCommand::class);
 }