public function testResetPassword()
 {
     $emailAddress = '*****@*****.**';
     $diamanteUser = new DiamanteUser($emailAddress, null, 'firstName', 'lastName');
     $apiUser = new ApiUser($emailAddress, null);
     $this->diamanteUserRepository->expects($this->once())->method('findUserByEmail')->with($this->equalTo($emailAddress))->will($this->returnValue($diamanteUser));
     $this->apiUserRepository->expects($this->once())->method('findUserByEmail')->with($this->equalTo($emailAddress))->will($this->returnValue($apiUser));
     $this->apiUserRepository->expects($this->once())->method('store')->with($apiUser);
     $this->resetPasswordMailer->expects($this->once())->method('sendResetEmail')->with($emailAddress, $apiUser->getHash());
     $command = new ResetPasswordCommand();
     $command->email = $emailAddress;
     $this->resetPasswordService->resetPassword($command);
 }
 /**
  * @param ResetPasswordCommand $command
  * @return void
  * @throws \RuntimeException if given emailAddres is not equal to generated one for user
  */
 public function resetPassword(ResetPasswordCommand $command)
 {
     /**
      * @var DiamanteUser $diamanteUser
      */
     $diamanteUser = $this->diamanteUserRepository->findUserByEmail($command->email);
     if (is_null($diamanteUser)) {
         throw new \RuntimeException('No accounts with that email found.');
     }
     /**
      * @var ApiUser $apiUser
      */
     $apiUser = $this->apiUserRepository->findUserByEmail($command->email);
     if (is_null($apiUser)) {
         $apiUser = $this->apiUserFactory->create($command->email, sha1(microtime(true), true));
     }
     $apiUser->generateHash();
     $this->apiUserRepository->store($apiUser);
     $this->resetPasswordMailer->sendResetEmail($diamanteUser->getEmail(), $apiUser->getHash());
 }