cyber-duck/mailgrasp

此包已被弃用,不再维护。作者建议使用cyber-duck/mailgrasp包。

为Laravel应用程序(5.1)添加测试类中电子邮件测试支持的包。

1.1.1 2017-02-02 21:55 UTC

This package is auto-updated.

Last update: 2021-10-26 09:54:23 UTC


README

此功能在Laravel的后续版本中已可直接使用。

MailGrasp

Build Status Latest Stable Version Total Downloads License

MailGrasp是一个用于Laravel应用程序(5.1+)的包,用于在测试类中添加电子邮件测试支持。

作者: Simone Todaro

Cyber-Duck Ltd用❤️制作

安装

composer require cyber-duck/mailgrasp --dev

用法

InteractsWithEmails添加到您的测试类。就这样!

use \Cyberduck\MailGrasp\Testing\InteractsWithEmails;

当调用visit()方法时,将初始化自定义邮件发送器。

查看邮件

检查是否恰好发送或入队了$count封邮件。

$this->visit('/route/which/sends/2/emails')
    ->seeEmails(2);

查看队列中的邮件

检查是否恰好入队了$count封邮件。

$this->visit('/route/which/enqueues/2/emails')
    ->seeEmailsInQueue(2);

不查看邮件 / 不查看邮件

检查是否没有发送或入队任何邮件。

$this->visit('/route/with/no/emails')
    ->dontSeeEmails();

// OR

$this->visit('/route/with/no/emails')
    ->notSeeEmails();

不查看队列中的邮件 / 不查看队列中的邮件

检查是否没有入队任何邮件。

$this->visit('/route/with/no/emails')
    ->dontSeeEmailsInQueue();

// OR

$this->visit('/route/with/no/emails')
    ->notSeeEmailsInQueue();

查看邮件

检查是否发送或入队了与给定条件匹配的邮件。

$this->visit('/route/which/sends/emails')
    ->seeEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->seeEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

不查看邮件

与查看邮件相反。

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

查看队列中的邮件

检查是否入队了与给定条件匹配的邮件。

$this->visit('/route/which/enqueues/emails')
    ->seeEmailInQueue(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->seeEmailInQueue($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

在邮件中查看

检查与给定条件匹配的邮件是否包含给定的字符串。

$this->visit('/route/which/sends/emails')
    ->seeInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    }, 'Lorem ipsum dolor sit amet');

// OR

$this->visit('/route/which/sends/emails')
    ->seeInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    }, 'Lorem ipsum dolor sit amet);

在邮件中点击

访问邮件链接中的页面。用于测试激活链接非常有用。

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

如果邮件中有多于一个链接,可以通过传递CSS选择器作为第二个参数来选择链接。

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    }, 'a.activation-link');

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    }, 'a.activation-link');