本文整理汇总了PHP中Swift_Mailer::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Mailer::expects方法的具体用法?PHP Swift_Mailer::expects怎么用?PHP Swift_Mailer::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Mailer
的用法示例。
在下文中一共展示了Swift_Mailer::expects方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSendWithMailRendered
/**
* @dataProvider getHtmlValues
*
* @param string|null $htmlValue
*/
public function testSendWithMailRendered($htmlValue)
{
$message = $this->getMockBuilder(\Swift_Message::class)->disableOriginalConstructor()->getMock();
/* @var MailRenderedInterface|\PHPUnit_Framework_MockObject_MockObject $mail */
$mail = $this->getMockBuilder(MailRenderedInterface::class)->getMock();
$mail->expects($this->once())->method('getSubject')->will($this->returnValue('Subject'));
$mail->expects($this->once())->method('getHTMLBody')->will($this->returnValue($htmlValue));
$mail->expects($this->once())->method('getBody')->will($this->returnValue('Body'));
$this->swiftMailer->expects($this->at(0))->method('send')->with($message)->will($this->returnValue(1));
$this->assertTrue($this->transport->send($message, $mail));
}
示例2: testSendEmail
/**
* Tests the sendEmail method.
*/
public function testSendEmail()
{
$message = new Message();
$message->setBody(array('subject' => 'subject', 'from' => array('email' => 'from@mail.fr', 'name' => 'nameFrom'), 'to' => array('to1@mail.fr', 'to2@mail.fr' => 'nameTo2'), 'replyTo' => array('replyTo1@mail.fr', 'replyTo2@mail.fr' => 'nameReplyTo2'), 'message' => array('text' => 'message text', 'html' => 'message html')));
$mail = $this->getMockBuilder('Swift_Message')->disableOriginalConstructor()->getMock();
$mail->expects($this->once())->method('setSubject')->with($this->equalTo('subject'))->willReturnSelf();
$mail->expects($this->once())->method('setFrom')->with($this->equalTo(array('from@mail.fr' => 'nameFrom')))->willReturnSelf();
$mail->expects($this->once())->method('setTo')->with($this->equalTo(array('to1@mail.fr', 'to2@mail.fr' => 'nameTo2')))->willReturnSelf();
$mail->expects($this->once())->method('setReplyTo')->with($this->equalTo(array('replyTo1@mail.fr', 'replyTo2@mail.fr' => 'nameReplyTo2')))->willReturnSelf();
$mail->expects($this->exactly(2))->method('addPart')->withConsecutive(array($this->equalTo('message text'), $this->equalTo('text/plain')), array($this->equalTo('message html'), $this->equalTo('text/html')))->willReturnSelf();
$this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($mail));
$method = new \ReflectionMethod($this->consumer, 'sendEmail');
$method->setAccessible(true);
$method->invoke($this->consumer, $message);
}
示例3: testMessageSubjectFormatting
public function testMessageSubjectFormatting()
{
// Wire Mailer to expect a specific Swift_Message with a customized Subject
$messageTemplate = new \Swift_Message();
$messageTemplate->setSubject('Alert: %level_name% %message%');
$receivedMessage = null;
$this->mailer->expects($this->once())->method('send')->with($this->callback(function ($value) use(&$receivedMessage) {
$receivedMessage = $value;
return true;
}));
$handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
$records = array($this->getRecord(Logger::EMERGENCY));
$handler->handleBatch($records);
$this->assertEquals('Alert: EMERGENCY test', $receivedMessage->getSubject());
}
示例4: testNotifyWithEmptyAuthor
public function testNotifyWithEmptyAuthor()
{
$ticketUniqueId = UniqueId::generate();
$reporter = new UserAdapter(1, UserAdapter::TYPE_DIAMANTE);
$assignee = new User();
$assignee->setId(2);
$assignee->setEmail('assignee@host.com');
$author = null;
$branch = new Branch('KEY', 'Name', 'Description');
$ticket = new Ticket($ticketUniqueId, new TicketSequenceNumber(1), 'Subject', 'Description', $branch, $reporter, $assignee, new Source(Source::WEB), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::NEW_ONE));
$notification = new TicketNotification((string) $ticketUniqueId, $author, 'Header', 'Subject', new \ArrayIterator(array('key' => 'value')), array('file.ext'));
$message = new \Swift_Message();
$this->watchersService->expects($this->once())->method('getWatchers')->will($this->returnValue([new WatcherList($ticket, 'diamante_1')]));
$this->diamanteUserRepository->expects($this->exactly(2))->method('get')->with(1)->will($this->returnValue($this->diamanteUser));
$this->configManager->expects($this->once())->method('get')->will($this->returnValue('test@gmail.com'));
$this->nameFormatter->expects($this->once())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last'));
$this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$this->ticketRepository->expects($this->once())->method('getByUniqueId')->with($ticketUniqueId)->will($this->returnValue($ticket));
$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('changes'), $this->arrayHasKey('attachments'), $this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains($notification->getChangeList()), $this->contains($notification->getAttachments()), $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->getSubject(), $notification->getSubject()) && false !== strpos($other->getSubject(), 'KEY-1') && false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('reporter@host.com', $to) && $other->getHeaders()->has('References') && false !== strpos($other->getHeaders()->get('References'), 'id_1@host.com') && false !== strpos($other->getHeaders()->get('References'), 'id_2@host.com');
})));
$this->messageReferenceRepository->expects($this->once())->method('findAllByTicket')->with($ticket)->will($this->returnValue(array(new MessageReference('id_1@host.com', $ticket), new MessageReference('id_2@host.com', $ticket))));
$this->messageReferenceRepository->expects($this->once())->method('store')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\EmailProcessing\\MessageReference')));
$notifier = new EmailNotifier($this->container, $this->twig, $this->mailer, $this->templateResolver, $this->ticketRepository, $this->messageReferenceRepository, $this->userService, $this->nameFormatter, $this->diamanteUserRepository, $this->configManager, $this->oroUserManager, $this->watchersService, $this->senderHost);
$notifier->notify($notification);
}
示例5: testMessageCanBeCustomizedGivenLoggedData
public function testMessageCanBeCustomizedGivenLoggedData()
{
// Wire Mailer to expect a specific Swift_Message with a customized Subject
$expectedMessage = new \Swift_Message();
$this->mailer->expects($this->once())->method('send')->with($this->callback(function ($value) use($expectedMessage) {
return $value instanceof \Swift_Message && $value->getSubject() === 'Emergency' && $value === $expectedMessage;
}));
// Callback dynamically changes subject based on number of logged records
$callback = function ($content, array $records) use($expectedMessage) {
$subject = count($records) > 0 ? 'Emergency' : 'Normal';
$expectedMessage->setSubject($subject);
return $expectedMessage;
};
$handler = new SwiftMailerHandler($this->mailer, $callback);
// Logging 1 record makes this an Emergency
$records = array($this->getRecord(Logger::EMERGENCY));
$handler->handleBatch($records);
}
示例6: testSendConfirmationEmail
public function testSendConfirmationEmail()
{
$email = 'test@email.com';
$activationHash = md5(time());
$fromEmail = 'from@email.com';
$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);
}
示例7: testNotify
public function testNotify()
{
$author = new ApiUser('reporter@host.com', '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('reporter@host.com', $to);
})));
$notifier = new EmailNotifier($this->twig, $this->mailer, $this->templateResolver, $this->userService, $this->nameFormatter, $this->configManager, $this->senderEmail);
$notifier->notify($notification);
}
示例8: testSendMessageWithNoBodyHtmlBlock
/**
* Tests the sendMessage method with no body_html block.
*/
public function testSendMessageWithNoBodyHtmlBlock()
{
$this->twig->expects($this->once())->method('loadTemplate')->will($this->returnValue($this->template));
$contact = new Contact();
$this->template->expects($this->exactly(3))->method('renderBlock')->withConsecutive(array($this->equalTo('subject'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_text'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_html'), $this->equalTo(array('contact' => $contact))))->willReturnOnConsecutiveCalls('', 'Body text', '');
$message = $this->getMockBuilder('\\Swift_Message')->disableOriginalConstructor()->getMock();
$message->expects($this->once())->method('setSubject')->willReturnSelf();
$message->expects($this->once())->method('setFrom')->willReturnSelf();
$message->expects($this->once())->method('setTo')->willReturnSelf();
$message->expects($this->once())->method('setBody')->with($this->equalTo('Body text'));
$message->expects($this->never())->method('addPart');
$this->serviceMailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$this->mailer->expects($this->once())->method('send')->with($this->equalTo($message));
$this->serviceMailer->sendMessage($contact);
}
示例9: assertSendCalled
/**
* @param string $templateName
* @param array $templateParams
* @param \Swift_Message $expectedMessage
* @param string $emailType
*/
protected function assertSendCalled($templateName, array $templateParams, \Swift_Message $expectedMessage, $emailType = 'txt')
{
$this->emailTemplate->expects($this->once())->method('getType')->willReturn($emailType);
$this->objectRepository->expects($this->once())->method('findOneBy')->with(['name' => $templateName])->willReturn($this->emailTemplate);
$this->renderer->expects($this->once())->method('compileMessage')->with($this->emailTemplate, $templateParams)->willReturn([$expectedMessage->getSubject(), $expectedMessage->getBody()]);
$to = $expectedMessage->getTo();
$toKeys = array_keys($to);
$this->emailHolderHelper->expects($this->once())->method('getEmail')->with($this->isInstanceOf('Oro\\Bundle\\UserBundle\\Entity\\UserInterface'))->willReturn(array_shift($toKeys));
$this->mailer->expects($this->once())->method('send')->with($this->callback(function (\Swift_Message $actualMessage) use($expectedMessage) {
$this->assertEquals($expectedMessage->getSubject(), $actualMessage->getSubject());
$this->assertEquals($expectedMessage->getFrom(), $actualMessage->getFrom());
$this->assertEquals($expectedMessage->getTo(), $actualMessage->getTo());
$this->assertEquals($expectedMessage->getBody(), $actualMessage->getBody());
$this->assertEquals($expectedMessage->getContentType(), $actualMessage->getContentType());
return true;
}));
}