2012-10-23 77 views
0

也许我已经过度复杂化了,但我有一个电子邮件对象被另一个类调用,而Email类使用Swift Mailer的一个实例。PHPUnit测试SwiftMail发送方法参数

$email = Email::instance(); 
$mailer = $this->getMock('Swift_Mailer', array('send'), array(new \Swift_NullTransport())); 
$email->setTransport($mailer); 
$mailer->expects($this->once()) 
    ->method('send'); 
$model->sendEmail('[email protected]'); 

正如上面我可以很容易地测试,如果发送方法被调用,并正确地确认该邮件被发送,但是,我需要测试从正在与发送的雨燕梅勒信息的主题邮件。

$email = Email::instance(); 
$mailer = $this->getMock('Swift_Mailer', array('send'), array(new \Swift_NullTransport())); 
$email->setTransport($mailer); 
$mailer->expects($this->once()) 
    ->method('send') 
    ->with($this->equalTo('new email subject')); 

很明显,这不起作用,并引发了很多错误。

任何想法,我怎么可以测试这个?

回答

0

找到解决方法。

而不是测试Swift邮件内容,我嘲笑模型和测试传递给调用电子邮件对象类的函数的参数。

绝对不漂亮,但它会解决上面的具体问题。