ericmartel/codeception-email-mailcatcher

为使用 MailCatcher 测试电子邮件功能时提供 Codeception 测试助手

1.0.3 2016-01-27 12:38 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:38 UTC


README

此 Codeception 模块实现了使用 Codeception 电子邮件测试框架MailCatcher 测试电子邮件所需的方法

安装

通过 composer,需要此包

"require-dev": {
        "ericmartel/codeception-email-mailcatcher": "^1.0"
    }

然后在您的 Codeception suite yaml 文件中启用它

class_name: FunctionalTester
modules:
    enabled:
        - MailCatcher
    config:
        MailCatcher:
            url: 'http://127.0.0.1'
            port: '1080'

可以使用 guzzleRequestOptions 变量直接向 Guzzle 连接提供附加参数。

变量 deleteEmailsAfterScenario 可以设置为 true,以确保在每个场景结束时删除所有电子邮件,但默认情况下是关闭的。

新增方法

此模块为用户添加了一些公共方法,例如

deleteAllEmails()

删除 MailCatcher 中的所有电子邮件

fetchEmails()

从 MailCatcher 获取所有电子邮件标题,按时间戳排序,并将它们分配给当前和未读收件箱

accessInboxFor($address)

筛选电子邮件,仅保留由提供的地址接收的电子邮件

openNextUnreadEmail()

弹出最新未读电子邮件,并将其分配为要执行测试的电子邮件

示例测试

这里是一个简单的场景,其中我们测试电子邮件的内容。有关所有可用测试方法的详细列表,请参阅 Codeception 电子邮件测试框架

<?php 
$I = new FunctionalTester($scenario);
$I->am('a member');
$I->wantTo('request a reset password link');

// First, remove all existing emails in the MailCatcher inbox
$I->deleteAllEmails();

// Implementation is up to the user, use this as an example
$I->requestAPasswordResetLink();

// Query MailCatcher 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

特此授予任何人无费用获得此软件及其相关文档文件(以下简称“软件”)的副本的权利,用于在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许获得软件的人执行这些操作,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、针对特定目的的适用性和非侵权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些索赔、损害或其他责任是基于合同、侵权或其他方式引起的,并且与软件或其使用或其他操作有关。