tpayne / behat-mail-extension
用于测试 Behat 邮件扩展的扩展
1.1
2018-05-30 18:39 UTC
Requires
- php: >=5.4
- behat/behat: ~3.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpspec/phpspec: ~2.1
This package is not auto-updated.
Last update: 2024-09-18 06:53:44 UTC
README
需求
- PHP 5.5 或更高版本
支持的驱动程序
安装
使用 composer 需要安装 tpayne/behat-mail-extension
composer require tpayne/behat-mail-extension --dev
或者手动将其添加到 composer.json
文件的 require-dev 部分。
"require-dev": {
"tpayne/behat-mail-extension": "~1.0"
},
配置您的上下文
设置您的功能上下文以使用 Behat 邮件扩展
-
在您的功能上下文中实现 MailAwareContext。
-
在您的上下文中使用 Mail 特性。
use tPayne\BehatMailExtension\Context\MailAwareContext;
use tPayne\BehatMailExtension\Context\MailTrait;
class FeatureContext implements MailAwareContext {
use MailTrait;
使用 mail 特性将在您的功能上下文中添加一个 mail 属性。
behat.yml
为您的 behat.yml
文件选择以下配置之一。
默认值
如果没有指定驱动程序,将使用以下默认值
driver
: mailcatcherbase_uri
: localhosthttp_port
: 1080
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension
MailCatcher
将 MailExtension 添加到您的 behat.yml
文件
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension:
driver: mailcatcher
base_uri: localhost # optional
http_port: 1080 # optional
Mailtrap.io
将 MailExtension 添加到您的 behat.yaml
文件
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension:
driver: mailtrap
api_key: MAIL_TRAP_KEY
mailbox_id: MAILBOX_ID
使用方法
当运行带有 @mail
标签的场景时,Behat 邮件扩展将自动清除收件箱中的消息。
Feature: App Registration
In order to join the site
As a guest
I want to register for an account
@mail
Scenario: Register an account
Given I am a guest
When I register for an account
Then I should receive a welcome email
从您的功能上下文中访问邮件属性以测试发送的任何电子邮件。
/**
* @Then I should receive a welcome email
*/
public function iShouldReceiveAWelcomeEmail()
{
$message = $this->mail->getLatestMessage();
PHPUnit_Framework_Assert::assertEquals('Welcome!', $message->subject());
PHPUnit_Framework_Assert::assertContains('Please confirm your account', $message->plainText());
}
邮件驱动程序 API
通过功能上下文中的邮件属性可访问邮件驱动程序,它提供了以下方法
getMessages()
getLatestMessage()
deleteMessages()
(在标记为@mail
的场景之后自动调用)
消息 API
邮件驱动程序将返回一个具有以下 API 的消息对象
to()
from()
subject()
plainText()
html()
date()