johnatannvmd / codeception-mailchecker-module
Requires
- php: >=5.4
- ext-imap: *
- ext-mailparse: *
- php-mime-mail-parser/php-mime-mail-parser: ~2.0
Requires (Dev)
- codeception/codeception: ^2.1
- guzzlehttp/guzzle: ^6.0
- satooshi/php-coveralls: ~1.0
- squizlabs/php_codesniffer: 2.*
- swiftmailer/swiftmailer: ^5.0
- zendframework/zend-mail: ^2.6
Suggests
- guzzlehttp/guzzle: Allow you to use MailCatcher, MailDump, LatherMail, MailTrap providers
- zendframework/zend-mail: Allow you to use ZendMail provider
This package is not auto-updated.
Last update: 2022-02-01 12:54:09 UTC
README
此存储库已废弃。请使用 https://github.com/captbaritone/codeception-mailcatcher-module 或其他类似项目。
此模块将允许您在Codeception验收测试期间测试发送的电子邮件。
它受到了 https://github.com/captbaritone/codeception-mailcatcher-module 和 https://github.com/fetch/zend-mail-codeception-module/ 的启发。
它支持多个邮件测试工具
- MailCatcher
- MailDump
- ZendMail
- LatherMail
- MailHog
- Mailtrap
- [Imap 服务器] 包含
安装
将包添加到您的 composer.json
。例如,我们为MailDump提供者添加了Guzzle库
{
"require-dev": {
"codeception/codeception": "*",
"johnatannvmd/mailchecker-codeception-module": "1.*"
}
}
告诉Composer下载此包
php composer.phar update
然后在您的 acceptance.suite.yml
配置中启用它,并设置您网站MailCatcher安装的URL和端口
class_name: WebGuy
modules:
enabled:
- MailChecker
config:
MailChecker:
provider: MailCatcher
options:
url: 'http://project.dev'
port: '1080'
可选配置
如果您需要指定一些特殊选项(例如SSL验证或身份验证头),您可以设置所有允许的 Guzzle请求选项
class_name: WebGuy
modules:
enabled:
- MailChecker
config:
MailChecker:
provider: MailDump
options:
url: 'http://project.dev'
port: '1080'
guzzleOptions:
auth: ['yo', 'yo']
示例用法
<?php
$I = new WebGuy($scenario);
$I->wantTo('Get a password reset email');
// Cleared old emails from MailCatcher
$I->clearMailbox();
// 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");
操作
clearMailbox
清除提供商列表中的电子邮件。这可以防止看到之前测试期间发送的电子邮件。您可能希望在触发任何电子邮件发送之前执行此操作。
示例
<?php
// Clears all emails
$I->clearMailbox();
?>
seeInLastEmail
检查电子邮件是否包含某个值。它搜索电子邮件的完整原始文本:头部、主题行和正文。
示例
<?php
$I->seeInLastEmail('Thanks for signing up!');
?>
- 参数 $text
seeInLastEmailTo
检查发送到地址的最后一封电子邮件是否包含某个值。它搜索电子邮件的完整原始文本:头部、主题行和正文。
这在例如,一个页面同时触发了发送给新用户和给管理员的电子邮件时很有用。
示例
<?php
$I->seeInLastEmailTo('user@example.com', 'Thanks for signing up!');
$I->seeInLastEmailTo('admin@example.com', 'A new user has signed up!');
?>
- 参数 $email
- 参数 $text
dontSeeInLastEmail
检查电子邮件是否不包含某个值。它搜索电子邮件的完整原始文本:头部、主题行和正文。
示例
<?php
$I->dontSeeInLastEmail('Hit me with those laser beams');
?>
- 参数 $text
dontSeeInLastEmailTo
检查发送到地址的最后一封电子邮件是否不包含某个值。它搜索电子邮件的完整原始文本:头部、主题行和正文。
示例
<?php
$I->dontSeeInLastEmailTo('admin@example.com', 'But shoot it in the right direction');
?>
- 参数 $email
- 参数 $text
查看上封邮件的附件文件名
检查上封邮件是否有以下文件名的附件。
示例
<?php
$I->seeAttachmentFilenameInLastEmail('expected_journey.ext');
?>
- 参数 $expectedFilename
不查看上封邮件的附件文件名
检查上封邮件没有以下文件名的附件。
示例
<?php
$I->dontSeeAttachmentFilenameInLastEmail('unexpected_journey.ext');
?>
- 参数 $unexpectedFilename
查看发送到指定地址的邮件的附件文件名
检查发送到指定地址的邮件是否有以下文件名的附件。
示例
<?php
$I->seeAttachmentFilenameInLastEmailTo('admin@example.com', 'expected_journey.ext');
?>
- 参数 $address
- 参数 $expectedFilename
不查看发送到指定地址的邮件的附件文件名
检查发送到指定地址的邮件没有以下文件名的附件。
示例
<?php
$I->dontSeeAttachmentFilenameInLastEmailTo('admin@example.com', 'unexpected_journey.ext');
?>
- 参数 $address
- 参数 $unexpectedFilename
查看上封邮件的附件数量
断言在上封邮件中找到特定数量的附件。
示例
<?php
$I->seeAttachmentsCountInLastEmail(1);
?>
- 参数 $exected
查看发送到指定地址的邮件的附件数量
断言在发送到指定地址的邮件中找到特定数量的附件。
示例
<?php
$I->seeAttachmentsCountInLastEmailTo('admin@example.com', 1);
?>
- 参数 $address
- 参数 $expected
查看上封邮件中的抄送地址
在上封发送的邮件中查找预期的抄送地址。
示例
<?php
$I->seeCcInLastEmail('cc@example.com');
?>
- 参数 $expectedAddress
查看发送到指定地址的邮件中的抄送地址
在上封发送到指定地址的邮件中查找预期的抄送地址。
示例
<?php
$I->seeCcInLastEmailTo('admin@example.com', 'cc@example.com');
?>
- 参数 $address
- 参数 $expectedAddress
从上封邮件中提取匹配项
根据正则表达式从上封邮件中提取匹配项和子匹配项的数组。它搜索邮件的全部原始文本:头部、主题行和正文。返回值类似于 preg_match()
返回的数组。
示例
<?php
$matches = $I->grabMatchesFromLastEmail('@<strong>(.*)</strong>@');
?>
- 参数 $regex
从上封邮件中提取字符串
根据正则表达式从上封邮件中提取字符串。它搜索邮件的全部原始文本:头部、主题行和正文。
示例
<?php
$match = $I->grabFromLastEmail('@<strong>(.*)</strong>@');
?>
- 参数 $regex
从上封邮件中提取匹配项
根据正则表达式从上封邮件到指定地址中提取匹配项和子匹配项的数组。它搜索邮件的全部原始文本:头部、主题行和正文。返回值类似于 preg_match()
返回的数组。
示例
<?php
$matchs = $I->grabMatchesFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
?>
- 参数 $email
- 参数 $regex
从上封邮件中提取字符串
根据正则表达式从上封邮件到指定地址中提取字符串。它搜索邮件的全部原始文本:头部、主题行和正文。
示例
<?php
$match = $I->grabFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
?>
- 参数 $email
- 参数 $regex
查看邮件数量
断言自上次调用 clearMailbox()
以来发送了特定数量的邮件。
示例
<?php
$match = $I->seeEmailCount(2);
?>
- 参数 $count
Docker
现在您可以一次性构建所有模块
docker-compose build
许可证
在相同的许可证下发布,与Codeception相同:MIT许可证