public function testNotify()
 {
     $author = new ApiUser('*****@*****.**', 'password');
     $notification = new UserNotification($author, 'Header');
     $format = '%prefix% %first_name% %middle_name% %last_name% %suffix%';
     $message = new \Swift_Message();
     $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
     $this->configManager->expects($this->once())->method('get')->will($this->returnValue('Mike The Bot'));
     $this->nameFormatter->expects($this->any())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last'));
     $this->userService->expects($this->once())->method('verifyDiamanteUserExists')->with($this->equalTo($author->getEmail()))->will($this->returnValue(1));
     $this->userService->expects($this->once())->method('getByUser')->with($this->equalTo(new UserAdapter(1, UserAdapter::TYPE_DIAMANTE)))->will($this->returnValue($this->diamanteUser));
     $this->nameFormatter->expects($this->once())->method('getNameFormat')->will($this->returnValue($format));
     $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html'))));
     $optionsConstraint = $this->logicalAnd($this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains('First  Last'), $this->contains($notification->getHeaderText()));
     $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template'));
     $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template'));
     $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) {
         $to = $other->getTo();
         return false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to);
     })));
     $notifier = new EmailNotifier($this->twig, $this->mailer, $this->templateResolver, $this->userService, $this->nameFormatter, $this->configManager, $this->senderEmail);
     $notifier->notify($notification);
 }
 /**
  * @param ApiUser $apiUser
  * @return DiamanteUser|null
  */
 public function getUserFromApiUser(ApiUser $apiUser)
 {
     return $this->diamanteUserRepository->findUserByEmail($apiUser->getEmail());
 }