ericmartel / codeception-email-mailhog
为Codeception提供测试辅助工具,用于通过MailHog测试邮件功能
Requires
- ericmartel/codeception-email: ^1.0
- guzzlehttp/guzzle: ^6.1
README
此Codeception模块实现了使用Codeception Email Testing Framework和MailHog测试邮件所需的方法
安装
通过composer,需要此包
"require-dev": {
"ericmartel/codeception-email-mailhog": "^1.0"
}
然后在您的Codeception套件yaml文件中启用它
class_name: FunctionalTester
modules:
enabled:
- MailHog
config:
MailHog:
url: 'http://mailhog.dev'
port: '8025'
可以通过guzzleRequestOptions
变量直接向Guzzle连接传递附加参数。
可以将变量deleteEmailsAfterScenario
设置为true,以确保每个场景结束时删除所有邮件,但默认情况下它是关闭的。
添加的方法
此模块为用户添加了一些公共方法,例如
deleteAllEmails()
删除MailHog中的所有邮件
fetchEmails()
从MailHog获取所有邮件头,按时间戳排序并将它们分配给当前和未读收件箱
accessInboxFor($address)
过滤邮件,仅保留由提供的地址接收的邮件
openNextUnreadEmail()
弹出最新未读邮件,将其分配为测试的邮件
示例测试
这里是一个简单的场景,我们测试邮件的内容。有关所有可用测试方法的详细列表,请参阅Codeception Email Testing Framework。
<?php
$I = new FunctionalTester($scenario);
$I->am('a member');
$I->wantTo('request a reset password link');
// First, remove all existing emails in the MailHog inbox
$I->deleteAllEmails();
// Implementation is up to the user, use this as an example
$I->requestAPasswordResetLink();
// Query MailHog and fetch all available emails
$I->fetchEmails();
// This is optional, but will filter the emails in case you're sending multiple emails or use the BCC field
$I->accessInboxFor('testuser@example.com');
// A new email should be available and it should be unread
$I->haveEmails();
$I->haveUnreadEmails();
// Set the next unread email as the email to perform operations on
$I->openNextUnreadEmail();
// After opening the only available email, the unread inbox should be empty
$I->dontHaveUnreadEmails();
// Validate the content of the opened email, all of these operations are performed on the same email
$I->seeInOpenedEmailSubject('Your Password Reset Link');
$I->seeInOpenedEmailBody('Follow this link to reset your password');
$I->seeInOpenedEmailRecipients('testuser@example.com');
许可证
版权(c)2015-2016 Eric Martel,http://github.com/ericmartel emartel@gmail.com
特此授予任何获得此软件及其相关文档文件(“软件”)副本的任何人免费使用该软件的权利,不受限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向软件提供的人这样做,但受以下条件约束
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵权性的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他原因,是否因软件或其使用或其他方式引起、源自或与软件有关。