/**
  * Send user confirmation email
  * @param SendConfirmCommand $command
  * @return void
  */
 public function send(SendConfirmCommand $command)
 {
     $apiUser = $this->apiUserRepository->findUserByEmail($command->email);
     if (!$apiUser) {
         throw new EntityNotFoundException();
     }
     if ($apiUser->isActive()) {
         throw new \RuntimeException('User is already activated');
     }
     $apiUser->generateHash();
     $this->apiUserRepository->store($apiUser);
     $this->registrationMailer->sendConfirmationEmail($command->email, $apiUser->getHash());
 }
 public function testSendConfirmationEmail()
 {
     $email = '*****@*****.**';
     $activationHash = md5(time());
     $fromEmail = '*****@*****.**';
     $htmlTemplate = 'html.tpl';
     $txtTemplate = 'txt.tpl';
     $registrationMailer = new RegistrationMailer($this->twig, $this->mailer, $fromEmail, $htmlTemplate, $txtTemplate);
     $confirmation = new \Swift_Message();
     $renderedHtmlTpl = 'rendered html';
     $renderedTxtTpl = 'rendered txt';
     $this->twig->expects($this->at(0))->method('render')->with($txtTemplate)->will($this->returnValue($renderedTxtTpl));
     $this->twig->expects($this->at(1))->method('render')->with($htmlTemplate)->will($this->returnValue($renderedHtmlTpl));
     $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($confirmation));
     $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($email, $renderedTxtTpl, $fromEmail) {
         return $other->getSubject() == 'Confirmation' && $other->getBody() == $renderedTxtTpl && array_key_exists($email, $other->getTo()) && array_key_exists($fromEmail, $other->getReplyTo());
     })));
     $registrationMailer->sendConfirmationEmail($email, $activationHash);
 }