symfony1

Testing emails with symfony


I am testing emails with sfTestMailer (delivery stratagy is none) How can I extract some text from sent email body?


Solution

  • 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() ...