fetch/zend-mail-codeception-module

此包的最新版本(v1.0.0)没有提供许可证信息。

在您的Codeception验收测试中测试电子邮件

v1.0.0 2015-11-29 12:42 UTC

This package is auto-updated.

Last update: 2024-09-12 11:02:51 UTC


README

Build Status

此模块将允许您在Codeception验收测试中测试发送的电子邮件。

安装

将包添加到您的composer.json中

{
    "require-dev": {
        "codeception/codeception": "*",
        "fetch/zend-mail-codeception-module": "^1.0"
    }
}

告诉Composer下载包

php composer.phar update

更新您的Zend邮件配置以使用文件传输

function mail_filename(){
  return uniqid() . '.mail';
}

$transportOptions = new Zend\Mail\Transport\FileOptions([
  'path' => 'tests/_output/mail',
  'callback' => 'mail_filename'
]);
$transport = new Zend\Mail\Transport\File($transportOptions);

然后在您的acceptance.suite.yml配置中启用它,并设置传输目录的路径。

class_name: WebGuy
modules:
  enabled:
    - ZendMail
  config:
    ZendMail:
      path: 'tests/_output/mail'

然后您需要重新构建您的演员类

php codecept.phar build

示例用法

$I = new WebGuy($scenario);
$I->wantTo('Get a password reset email');

// Cleared old emails from path
$I->resetEmails();

// Reset
$I->amOnPage('forgotPassword.php');
$I->fillField("input[name='email']", 'user@example.com');
$I->click("Submit");
$I->see("Please check your email");

$I->seeInLastEmail("Please click this link to reset your password");

操作

resetEmails

清除消息目录中的电子邮件。这可以防止看到之前测试中发送的电子邮件。您可能在触发任何电子邮件发送之前想这样做

示例

// Clears all emails
$I->resetEmails();

seeInLastEmail

检查电子邮件是否包含值。它搜索电子邮件的完整原始文本:标题、主题行和正文。

示例

$I->seeInLastEmail('Thanks for signing up!');
  • 参数 $text

seeInLastEmailTo

检查发送到地址的最后一封电子邮件是否包含值。它搜索电子邮件的完整原始文本:标题、主题行和正文。

这在例如,一个页面同时触发对新用户和管理员的电子邮件时很有用。

示例

$I->seeInLastEmailTo('user@example.com', 'Thanks for signing up!');
$I->seeInLastEmailTo('admin@example.com', 'A new user has signed up!');
  • 参数 $email
  • 参数 $text

dontSeeInLastEmail

检查电子邮件是否不包含值。它搜索电子邮件的完整原始文本:标题、主题行和正文。

示例

$I->dontSeeInLastEmail('Hit me with those laser beams');
  • 参数 $text

dontSeeInLastEmailTo

检查发送到地址的最后一封电子邮件是否不包含值。它搜索电子邮件的完整原始文本:标题、主题行和正文。

示例

$I->dontSeeInLastEmailTo('admin@example.com', 'But shoot it in the right direction');
  • 参数 $email
  • 参数 $text

grabMatchesFromLastEmail

根据正则表达式从最后一封电子邮件中提取匹配项和子匹配项的数组。它搜索电子邮件的完整原始文本:标题、主题行和正文。返回值是一个类似于preg_match()返回的数组。

示例

$matches = $I->grabMatchesFromLastEmail('@<strong>(.*)</strong>@');
  • 参数 $regex

grabFromLastEmail

根据正则表达式从最后一封电子邮件中提取字符串。它搜索电子邮件的完整原始文本:标题、主题行和正文。

示例

$match = $I->grabFromLastEmail('@<strong>(.*)</strong>@');
  • 参数 $regex

grabMatchesFromLastEmailTo

根据正则表达式从指定地址的最后一封电子邮件中提取匹配项和子匹配项的数组。它搜索电子邮件的完整原始文本:标题、主题行和正文。返回值是一个类似于preg_match()返回的数组。

示例

$matchs = $I->grabMatchesFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
  • 参数 $email
  • 参数 $regex

grabFromLastEmailTo

根据正则表达式从指定地址的最后一封电子邮件中提取字符串。它搜索电子邮件的完整原始文本:标题、主题行和正文。

示例

$match = $I->grabFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
  • 参数 $email
  • 参数 $regex

seeEmailCount

断言自上次调用resetEmails()以来已发送特定数量的电子邮件。

示例

$match = $I->seeEmailCount(2);
  • 参数 $count

许可证

在与Codeception相同的许可证下发布:MIT