oqq/codeception-email-mailhog

提供测试辅助工具,用于使用 MailHog 测试 Codeception 的电子邮件功能

3.2.0 2023-12-19 10:20 UTC

This package is auto-updated.

Last update: 2024-09-19 12:21:33 UTC


README

此 Codeception 模块实现了使用 Codeception Email Testing FrameworkMailHog 测试电子邮件所需的方法

安装

通过 composer,要求包

"require-dev": {
    "oqq/codeception-email-mailhog": "^2.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()

弹出最新未读电子邮件,并将其作为测试电子邮件

grabHeadersFromEmail()

从打开的电子邮件中获取标题,并以数组形式返回

示例测试

以下是一个简单的场景,我们测试电子邮件的内容。有关所有可用测试方法的详细列表,请参阅 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

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

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

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