/**
  * Register new Diamante User and grant API access for it.
  * Sends confirmation email. While registration is not confirmed API access is not active
  * @param Command\RegisterCommand $command
  * @return void
  */
 public function register(Command\RegisterCommand $command)
 {
     $diamanteUser = $this->diamanteUserFactory->create($command->email, $command->firstName, $command->lastName);
     $apiUser = $this->apiUserFactory->create($command->email, $command->password);
     if ($this->diamanteUserRepository->findUserByEmail($command->email)) {
         throw new \RuntimeException('An account with this email address already exists');
     }
     $diamanteUser->setApiUser($apiUser);
     $this->diamanteUserRepository->store($diamanteUser);
     $this->registrationMailer->sendConfirmationEmail($diamanteUser->getEmail(), $apiUser->getHash());
 }
 public function testRegister()
 {
     $apiUser = $this->createApiUser();
     $diamanteUser = $this->createDiamanteUser();
     $this->diamanteUserFactory->expects($this->once())->method('create')->with($diamanteUser->getEmail(), $diamanteUser->getFirstName(), $diamanteUser->getLastName())->will($this->returnValue($diamanteUser));
     $this->apiUserFactory->expects($this->once())->method('create')->with($apiUser->getEmail(), $apiUser->getPassword())->will($this->returnValue($apiUser));
     $this->diamanteUserRepository->expects($this->once())->method('store')->with($diamanteUser);
     $this->registrationMailer->expects($this->once())->method('sendConfirmationEmail')->with($diamanteUser->getEmail(), $apiUser->getHash());
     $command = new RegisterCommand();
     $command->email = $diamanteUser->getEmail();
     $command->password = $apiUser->getPassword();
     $command->firstName = $diamanteUser->getFirstName();
     $command->lastName = $diamanteUser->getLastName();
     $this->service->register($command);
 }