当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Template::expects方法代码示例

本文整理汇总了PHP中Twig_Template::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Template::expects方法的具体用法?PHP Twig_Template::expects怎么用?PHP Twig_Template::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Template的用法示例。


在下文中一共展示了Twig_Template::expects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:rkueny,项目名称:ContactBundle,代码行数:18,代码来源:TwigSwiftMailerTest.php

示例2: testRenderWithTwig

 public function testRenderWithTwig()
 {
     $this->templater->setLocale('fr');
     $layout = new TwigLayout(__DIR__ . '/../Fixtures/loaders/layout.html.twig');
     $layout->setName('test');
     $layoutTrans = new TwigLayoutTranslation($layout, __DIR__ . '/../Fixtures/loaders/layout.fr.html.twig');
     $layoutTrans->setLocale('fr');
     $mail = new TwigMail(__DIR__ . '/../Fixtures/loaders/mail.html.twig');
     $mailTrans = new TwigMailTranslation($mail, __DIR__ . '/../Fixtures/loaders/mail.fr.html.twig');
     $mailTrans->setLocale('fr');
     $mail->setLayout($layout);
     $trans = $mail->getTranslation('fr');
     $htmlRendered = $mail->getLayout()->getTranslation('fr')->getBody() . ' | ' . $trans->getHtmlBody();
     $twigVariables = array('_mail_type' => MailTypes::TYPE_ALL, '_layout' => 'test');
     $this->assertNull($mail->getTranslationDomain());
     $this->assertCount(1, $mail->getTranslations());
     $this->assertNotNull($mail->getLayout());
     $this->assertNull($mail->getLayout()->getTranslationDomain());
     $this->assertCount(1, $mail->getLayout()->getTranslations());
     $this->loader->expects($this->once())->method('load')->with('test', MailTypes::TYPE_ALL)->will($this->returnValue($mail));
     // render subject
     $this->twigTemplate->expects($this->at(0))->method('renderBlock')->with('subject', $twigVariables)->will($this->returnValue($trans->getSubject()));
     $twigVariables['_subject'] = $trans->getSubject();
     // render html body
     $this->twigTemplate->expects($this->at(1))->method('renderBlock')->with('html_body', $twigVariables)->will($this->returnValue($trans->getHtmlBody()));
     $twigVariables['_html_body'] = $trans->getHtmlBody();
     // render body
     $this->twigTemplate->expects($this->at(2))->method('renderBlock')->with('body', $twigVariables)->will($this->returnValue($trans->getBody()));
     $twigVariables['_body'] = $trans->getBody();
     // render layout
     $this->twigTemplate->expects($this->at(3))->method('renderBlock')->with('body', $twigVariables)->will($this->returnValue($htmlRendered));
     $rendered = $this->templater->render('test', array(), MailTypes::TYPE_ALL);
     $this->assertSame($trans->getSubject(), $rendered->getSubject());
     $this->assertSame($trans->getBody(), $rendered->getBody());
     $this->assertSame($htmlRendered, $rendered->getHtmlBody());
 }
开发者ID:sonatra,项目名称:SonatraMailerBundle,代码行数:36,代码来源:MailTemplaterTest.php


注:本文中的Twig_Template::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。