如何编写发送邮件的单元测试

时间:2017-05-02 14:10:09

标签: email yii2 codeception

我有一些发送电子邮件的代码:

class Mailer extends Component implements SenderContract
{
    const EVENT_SEND = 'send';

    public function init(){

        $this->on(self::EVENT_SEND, [$this, 'send']);

    }

    public function send(MessageContract $event)
    {
        \Yii::$app->mailer->compose(['html' => 'layouts/html'],
            ['content' => $event->getMessage()])
            ->setFrom([\Yii::$app->params['adminEmail'] => 'theme message'])
            ->setTo($event->getSender())
            ->setSubject('new message')
            ->send();
    }
}

我使用代码单元测试。我如何模拟send()方法?

0 个答案:

没有答案