PHPackages                             dmoen/mailtrap-test-helper - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. dmoen/mailtrap-test-helper

ActiveLibary[Mail &amp; Notifications](/categories/mail)

dmoen/mailtrap-test-helper
==========================

Test helper library for testing email submissions through Mailtrap, based on PHPUnit

v1.2.0(8y ago)08MITPHPPHP &gt;=5.5

Since Oct 6Pushed 8y agoCompare

[ Source](https://github.com/dmoen/mailtrap-test-helper)[ Packagist](https://packagist.org/packages/dmoen/mailtrap-test-helper)[ RSS](/packages/dmoen-mailtrap-test-helper/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (5)Used By (0)

Mailtrap test helper
====================

[](#mailtrap-test-helper)

Test helper library for testing email submissions through Mailtrap, based on PHPUnit.

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

[](#installation)

This package can be installed via Composer:

```
composer require dmoen/mailtrap-test-helper --dev
```

Usage
-----

[](#usage)

Create an instance of MailTrapInbox with api key and id of the inbox:

```
$inbox = new MailTrapInbox('api_key', 'inbox_id');
```

Example using a PHPUnit test case. Before each test the inbox should be cleaned:

```
private $inbox;

public function setUp()
{
    parent::setUp();

    $this->inbox = new MailTrapInbox('api_key', 'inbox_id'));
    $this->inbox->deleteAllMessages();
}
```

### Simple inbox testing

[](#simple-inbox-testing)

Test if the inbox has any messages:

```
$inbox->assertHasMails();
```

Test if the inbox has any messages from a specific address:

```
$inbox->assertHasMailFrom("sender@example.com");
```

With name:

```
$inbox->assertHasMailFrom("sender@example.com", "Sender Sendersson");
```

Test if the inbox has any messages to a specific address:

```
$inbox->assertHasMailFor("reciever@example.com");
```

With name:

```
$inbox->assertHasMailFor("reciever@example.com", "Receiver Receiversson");
```

Test if inbox has a message with a subject:

```
$inbox->assertHasMailWithSubject('Lorem subject');
```

Test if inbox has a message with a specific body:

```
$inbox->assertHasMailWithHtmlContent('Lorem ipsum sit amet');
$inbox->assertHasMailWithTextContent('Lorem ipsum sit amet');
```

### A bit more advanced testing for specific emails

[](#a-bit-more-advanced-testing-for-specific-emails)

To retrieve a specific message in the inbox:

```
$inbox->getLastMessage()
$inbox->getFirstMessage()
```

Or if you know the specific index in the inbox:

```
$message = $inbox->getMessage(2);
```

You can also search the inbox for a specific unique message using a condition:

```
$message = $inbox->findUnique(function($message){
    return $message->to_email == "receiver@example.com";
});
```

Or retrieve an array of all messages or by condition:

```
$messages = $inbox->fetchAllMessages();
```

```
$messages = $inbox->findMessages(function($message){
    return $message->to_email == "receiver@example.com";
});
```

The message instance passed to the closure has all the properties retrieved from the Mailtrap API:

The message(s) can then be tested with a combination of tests:

```
$message->assertIsFrom("me@railsware.com", "Private Person")
    ->assertIsFor("test@railsware.com", "A Test User")
    ->assertHasSubject("SMTP e-mail test")
    ->assertHasTextContent("This is a test e-mail message")
    ->assertHasHtmlContent("Lorem ipsum sit amet.");
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community3

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

3

Last Release

3136d ago

### Community

Maintainers

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

---

Top Contributors

[![dmoen](https://avatars.githubusercontent.com/u/31078956?v=4)](https://github.com/dmoen "dmoen (16 commits)")

### Embed Badge

![Health badge](/badges/dmoen-mailtrap-test-helper/health.svg)

```
[![Health](https://phpackages.com/badges/dmoen-mailtrap-test-helper/health.svg)](https://phpackages.com/packages/dmoen-mailtrap-test-helper)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

682104.9k7](/packages/guanguans-notify)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)

PHPackages © 2026

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