tpayne/behat-mail-extension
最新稳定版本:1.1
Composer 安装命令:
composer require tpayne/behat-mail-extension
包简介
An extension for testing emails with Behat
README 文档
README
Requirements
- PHP 5.5 or newer
Supported Drivers
Installation
Require tpayne/behat-mail-extension using composer
composer require tpayne/behat-mail-extension --dev
or add it manually to the require-dev section of your composer.json file.
"require-dev": {
"tpayne/behat-mail-extension": "~1.0"
},
Configure your context
Setup your feature context to use the Behat Mail Extension
-
Implement the MailAwareContext in your feature context.
-
Use the Mail trait in your context.
use tPayne\BehatMailExtension\Context\MailAwareContext;
use tPayne\BehatMailExtension\Context\MailTrait;
class FeatureContext implements MailAwareContext {
use MailTrait;
Using the mail trait will add a mail property to your feature context.
behat.yml
Chose one of the following configurations for your behat.yml file.
Defaults
If no drivers are specified the following defaults will be used:
driver: mailcatcherbase_uri: localhosthttp_port: 1080
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension
MailCatcher
Add the MailExtension to your behat.yml file:
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension:
driver: mailcatcher
base_uri: localhost # optional
http_port: 1080 # optional
Mailtrap.io
Add the MailExtension to your behat.yaml file:
default:
extensions:
tPayne\BehatMailExtension\ServiceContainer\MailExtension:
driver: mailtrap
api_key: MAIL_TRAP_KEY
mailbox_id: MAILBOX_ID
Usage
The Behat Mail Extension will automatically clear messages from the inbox when runing scenarios tagged with @mail
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
Access the mail property from your feature context to test any emails sent.
/**
* @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());
}
The Mail Driver API
The mail driver, accessible via the mail property on the feature context, offers the following methods:
getMessages()getLatestMessage()deleteMessages()(This is called automatically after scenarios tagged@mail)
The Message API
The mail driver will return a message object with the following API:
to()from()subject()plainText()html()date()
统计信息
- 总下载量: 79.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-02