lamoda / codeception-email-mailhog
为使用MailHog测试邮件功能提供Codeception测试辅助工具
Requires
- php: ^7.2
- ext-json: *
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- codeception/codeception: ^4.0
- ericmartel/codeception-email: ^1.0
- friendsofphp/php-cs-fixer: ^2.15.0
- phpunit/phpunit: ^8.0
Suggests
- ext-iconv: Will be used as a mime decoder (iconv_mime_decode)
- ext-mbstring: Will be used as a mime decoder if ext-iconv is not installed (mb_decode_mimeheader)
README
此Codeception模块实现了使用Codeception Email Testing Framework和MailHog测试电子邮件所需的方法
安装
通过composer,需要此包
"require-dev": {
"lamoda/codeception-email-mailhog": "^1.0"
}
然后在您的Codeception suite 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
特此授予任何获得此软件及其相关文档副本(“软件”)的人免费权利,使用软件而不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,以及允许获得软件的人这样做,但受以下条件约束
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的,还是基于商业性、特定用途和非侵权的保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论这些索赔、损害或其他责任是基于合同、侵权或其他方式产生的,与软件或其使用或其他交易有关。