2017 © Pedro Peláez
 

library behat-mail-extension

An extension for testing emails with Behat

image

tpayne/behat-mail-extension

An extension for testing emails with Behat

  • Wednesday, May 30, 2018
  • by tpayne
  • Repository
  • 1 Watchers
  • 5 Stars
  • 213 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 3 Versions
  • 15 % Grown

The README.md

Behat Mail Extension

Build Status, (*1)

Requirements

  • PHP 5.5 or newer

Supported Drivers

Installation

Require tpayne/behat-mail-extension using composer, (*2)

composer require tpayne/behat-mail-extension --dev

or add it manually to the require-dev section of your composer.json file., (*3)

"require-dev": {
    "tpayne/behat-mail-extension": "~1.0"
},

Configure your context

Setup your feature context to use the Behat Mail Extension, (*4)

1) Implement the MailAwareContext in your feature context., (*5)

2) Use the Mail trait in your context., (*6)

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., (*7)

behat.yml

Chose one of the following configurations for your behat.yml file., (*8)

Defaults

If no drivers are specified the following defaults will be used:, (*9)

  • driver: mailcatcher
  • base_uri: localhost
  • http_port: 1080
default:
    extensions:
        tPayne\BehatMailExtension\ServiceContainer\MailExtension

MailCatcher

Add the MailExtension to your behat.yml file:, (*10)

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:, (*11)

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, (*12)

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., (*13)

    /**
     * @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:, (*14)

  • 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:, (*15)

  • to()
  • from()
  • subject()
  • plainText()
  • html()
  • date()

The Versions

30/05 2018

dev-master

9999999-dev

An extension for testing emails with Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Payne

03/02 2015

dev-develop

dev-develop

An extension for testing emails with Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Payne

02/02 2015

1.0

1.0.0.0

An extension for testing emails with Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tyler Payne