PHPackages                             tpayne/behat-mail-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. tpayne/behat-mail-extension

ActiveLibrary[Testing &amp; Quality](/categories/testing)

tpayne/behat-mail-extension
===========================

An extension for testing emails with Behat

1.1(7y ago)879.5k4[1 issues](https://github.com/tyler43636/Behat-Mail-Extension/issues)MITPHPPHP &gt;=5.4

Since Feb 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tyler43636/Behat-Mail-Extension)[ Packagist](https://packagist.org/packages/tpayne/behat-mail-extension)[ RSS](/packages/tpayne-behat-mail-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

Behat Mail Extension
====================

[](#behat-mail-extension)

[![Build Status](https://camo.githubusercontent.com/d8629a3ddd13f9139848bd7be49ad1f2a05d7e9704fb6006bd1e83cb28c08f09/68747470733a2f2f7472617669732d63692e6f72672f74796c657234333633362f42656861742d4d61696c2d457874656e73696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tyler43636/Behat-Mail-Extension)

Requirements
------------

[](#requirements)

- PHP 5.5 or newer

Supported Drivers
-----------------

[](#supported-drivers)

- [MailCatcher](http://mailcatcher.me/)
- [Mailtrap.io](https://mailtrap.io/)

Installation
------------

[](#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
----------------------

[](#configure-your-context)

Setup your feature context to use the Behat Mail Extension

1. Implement the MailAwareContext in your feature context.
2. Use the Mail [trait](http://php.net/manual/en/language.oop5.traits.php) 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
---------

[](#behatyml)

Chose one of the following configurations for your `behat.yml` file.

### Defaults

[](#defaults)

If no drivers are specified the following defaults will be used:

- `driver`: **mailcatcher**
- `base_uri`: **localhost**
- `http_port`: **1080**

```
default:
    extensions:
        tPayne\BehatMailExtension\ServiceContainer\MailExtension

```

### MailCatcher

[](#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

[](#mailtrapio)

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
-----

[](#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-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-message-api)

The mail driver will return a message object with the following API:

- `to()`
- `from()`
- `subject()`
- `plainText()`
- `html()`
- `date()`

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 68.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1213 days

Total

2

Last Release

2901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b478e24d861417399873998aa379c604c0e2fc0eeb7b91342109058e815d9773?d=identicon)[tpayne](/maintainers/tpayne)

---

Top Contributors

[![tyler43636](https://avatars.githubusercontent.com/u/643589?v=4)](https://github.com/tyler43636 "tyler43636 (11 commits)")[![tyler-payne-wmu](https://avatars.githubusercontent.com/u/222224130?v=4)](https://github.com/tyler-payne-wmu "tyler-payne-wmu (4 commits)")[![AlexSkrypnyk](https://avatars.githubusercontent.com/u/378794?v=4)](https://github.com/AlexSkrypnyk "AlexSkrypnyk (1 commits)")

### Embed Badge

![Health badge](/badges/tpayne-behat-mail-extension/health.svg)

```
[![Health](https://phpackages.com/badges/tpayne-behat-mail-extension/health.svg)](https://phpackages.com/packages/tpayne-behat-mail-extension)
```

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

22215.1M146](/packages/drupal-drupal-extension)[friends-of-behat/variadic-extension

Variadic support for behat context arguments

2286.0M441](/packages/friends-of-behat-variadic-extension)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[imbo/behat-api-extension

API extension for Behat

1082.5M9](/packages/imbo-behat-api-extension)[drevops/behat-steps

Collection of steps for Behat

25381.7k3](/packages/drevops-behat-steps)[friends-of-behat/test-context

Provides reusable context that helps in testing Behat extensions.

1722.0k12](/packages/friends-of-behat-test-context)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
