/**
  * Handles a CreateUserCommand
  *
  * @param  CreateUserCommand $command
  */
 public function handleCreateUserCommand(CreateUserCommand $command)
 {
     $user = null;
     $originalUser = $command->getOriginalUser();
     ContextContainer::setContext($command->getContext());
     try {
         $user = $this->createUser($command->getId(), $originalUser, $command->getPreferredLanguage());
         $this->userManager->save($user);
         $this->logger->info('User Created');
     } catch (\Exception $e) {
         $this->logger->error('Error creating the user');
         $this->errorHandler->handle(new UnableToCreateUserEvent($command->getId(), new UndefinedApplicationUser($this->accountFactory->build($originalUser))), $command->getContext());
     }
     ContextContainer::reset();
 }
 private function assertErrorWillBeHandled()
 {
     $this->accountFactory->shouldReceive('build')->andReturn($this->account);
     $this->errorHandler->shouldReceive('handle')->with(\Mockery::on(function ($event) {
         return $event instanceof UnableToCreateUserEvent;
     }), null)->once();
 }