ericmartel/ codeception-email-mailtrap
为Codeception提供测试辅助工具,以便在Mailtrap上测试邮件功能
Requires
- ericmartel/codeception-email: ^1.0
- guzzlehttp/guzzle: ^6.1
This package is not auto-updated.
Last update: 2024-09-14 18:26:25 UTC
README
此Codeception模块实现了使用Codeception Email Testing Framework和Mailtrap测试邮件所需的方法
安装
通过composer,安装该包
"require-dev": {
"ericmartel/codeception-email-mailtrap": "^1.0"
}
然后在Codeception套件yaml文件中启用它
class_name: FunctionalTester
modules:
enabled:
- Mailtrap
config:
Mailtrap:
api_token: 'your token'
inbox_id: 'the inbox id you're using'
可以通过访问您的Mailtrap的API页面找到api_token
。点击您的邮箱之一将给出URL中的id,例如,https://mailtrap.io/inboxes/12345/settings
表示inbox_id
是12345
。
可以使用guzzleRequestOptions
变量直接向Guzzle连接传递额外的参数。
可以将变量deleteEmailsAfterScenario
设置为true,以确保在每个场景结束时删除所有邮件,但默认情况下它是关闭的。
添加的方法
此模块为用户添加了一些公开方法,例如
deleteAllEmails()
删除Mailtrap中的所有邮件
fetchEmails()
从Mailtrap获取所有邮件头,按时间戳排序,并将它们分配给当前和未读邮箱
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 Mailtrap inbox
$I->deleteAllEmails();
// Implementation is up to the user, use this as an example
$I->requestAPasswordResetLink();
// Query Mailtrap 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
特此授予任何获得此软件及其相关文档文件(“软件”)副本的任何人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许获得软件的人这样做,但受以下条件约束
上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任是因合同、侵权或其他方式引起的,无论是在软件或其使用或其它交易中产生的。