Testing emails with symfony
I am testing emails with sfTestMailer (delivery stratagy is none) How can I extrac开发者_运维知识库t some text from sent email body?
I think you would have to extend the sfTesterMailer to get the message (which is there, but is protected). Right in your functional test maybe you can do this:
class myTesterMailer extends sfTesterMailer {
public function getMessage() {
return $this->message;
}
}
class myTestFunc extends sfTestFunctional {
public function getMessage() {
$message = $this->with('mailer')->getMessage();
return $message;
}
}
$browser = new myTestFunc(new sfBrowser(), null, array('mailer' => 'myTesterMailer'));
$message = $browser->getMessage();
... do tests on $message->getBody() ...
If you have properly configured your factories, this should work:
$browser->
//the rest of your test here
with('mailer')->begin()->
checkHeader('Subject', '/Hello world/')->
checkBody('/Hello stack overflow/')->
end();
More info is available in the documentation.
精彩评论