コード例 #1
0
 function it_can_be_transformed(EngineInterface $templating, FilterChainInterface $filterChain, MailUserInterface $recipient1, MailUserInterface $recipient2, Attachment $attachment)
 {
     $html = '<html><head></head><body>Test</body></html>';
     $templating->render(Argument::type('string'), Argument::type('array'))->willReturn($html);
     $filterChain->apply(Argument::type('string'), Argument::any())->willReturn($html);
     $recipient1->getFullName()->willReturn('Test recipient 1');
     $recipient1->getEmail()->willReturn('*****@*****.**');
     $recipient2->getFullName()->willReturn('Test recipient 2');
     $recipient2->getEmail()->willReturn('*****@*****.**');
     $attachmentFileName = 'test.txt';
     $attachment->getData()->willReturn('test');
     $attachment->getFilename()->willReturn($attachmentFileName);
     $attachment->getContentType()->willReturn('text');
     $this->addRecipients([$recipient1, $recipient2]);
     $this->addBccRecipients([$recipient1, $recipient2]);
     $this->addAttachment($attachment);
     $message = $this->transform($templating, $filterChain, array(array('view' => 'default', 'contentType' => 'text/html')));
     $message->shouldHaveType('\\Swift_Message');
     $message->getSubject()->shouldBeLike(self::SUBJECT);
     $message->getBody()->shouldBeLike($html);
     $message->getFrom()->shouldBeLike(array(self::SENDER_EMAIL => self::SENDER_NAME));
     $message->getTo()->shouldHaveCount(2);
     $message->getBcc()->shouldHaveCount(2);
     $message->getChildren()->shouldHaveCount(1);
     // 1 attachment
     $attachment = $message->getChildren()[0];
     $attachment->shouldHaveType('Swift_Mime_Attachment');
     $attachment->getFileName()->shouldBeLike($attachmentFileName);
 }
コード例 #2
0
 function let(MailUserInterface $sender, MailUserInterface $recipient)
 {
     $sender->getEmail()->willReturn(self::SENDER_EMAIL);
     $sender->getFullName()->willReturn(self::SENDER_NAME);
     $recipient->getEmail()->willReturn(self::RECIPIENT_EMAIL);
     $recipient->getFullName()->willReturn(self::RECIPIENT_NAME);
     $this->beConstructedWith($sender, $recipient, self::SUBJECT, self::TEMPLATE, self::PRIORITY);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function transform(EngineInterface $templating, FilterChainInterface $filterChain, array $templates)
 {
     $message = $this->createSwiftMessage();
     $message->setTo($this->recipient->getEmail(), $this->recipient->getFullName());
     $body = $templating->render($templates[0]['view'], $this->parameters);
     $body = $filterChain->apply($body, $message);
     $message->setBody($body, $templates[0]['contentType']);
     for ($i = 1; $i < count($templates); $i++) {
         $part = $templating->render($templates[$i]['view'], $this->parameters);
         $part = $filterChain->apply($part, $message);
         $message->addPart($part, $templates[$i]['contentType']);
     }
     return $message;
 }
コード例 #4
0
 /**
  * Get user model
  * MailUserInterface might have additional data which is not needed, so it should be transformed to a minimal model
  * Besides if anything inside user gets changed, the changes will not be visible in the new User object, which is desirable behavior.
  * @param MailUserInterface $user
  * @return User
  */
 protected function getUserModel(MailUserInterface $user)
 {
     return new User($user->getEmail(), $user->getFullName());
 }
コード例 #5
0
 function let(MailUserInterface $user)
 {
     $user->getEmail()->willReturn(UserSpec::EMAIL);
     $user->getFullName()->willReturn(UserSpec::NAME);
     $this->beConstructedWith(self::TEMPLATE_DEFAULT);
 }