PHPackages                             jtproductions/mailtrap-assertions - 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. jtproductions/mailtrap-assertions

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

jtproductions/mailtrap-assertions
=================================

Assertions for PHPUnit to use with Mailtrap mailbox

v1.0.2(5y ago)026MITPHPPHP ^7.3

Since Jan 4Pushed 5y agoCompare

[ Source](https://github.com/JT-Productions/mailtrap-assertions)[ Packagist](https://packagist.org/packages/jtproductions/mailtrap-assertions)[ RSS](/packages/jtproductions-mailtrap-assertions/feed)WikiDiscussions main Synced 3d ago

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

Mailtrap assertsions to use in phpunit tests
============================================

[](#mailtrap-assertsions-to-use-in-phpunit-tests)

[![](https://camo.githubusercontent.com/c5d05a8702b21a45276df48e7cc07a37ea908a98365100a0fa6fbda237684dfa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73)](https://camo.githubusercontent.com/c5d05a8702b21a45276df48e7cc07a37ea908a98365100a0fa6fbda237684dfa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73) [![](https://camo.githubusercontent.com/190204ceb4218a99b786245b7d5ed6bcb7ceaffaec35a1019602166b19bccbdb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73)](https://camo.githubusercontent.com/190204ceb4218a99b786245b7d5ed6bcb7ceaffaec35a1019602166b19bccbdb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73) [![](https://camo.githubusercontent.com/395fad81932fcfac1de2f9ece4e80f6ea5cc81e09ec9787ec46a5f8279399d10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a7470726f64756374696f6e732f6d61696c747261702d617373657274696f6e733f636f6c6f723d73756363657373)](https://camo.githubusercontent.com/395fad81932fcfac1de2f9ece4e80f6ea5cc81e09ec9787ec46a5f8279399d10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a7470726f64756374696f6e732f6d61696c747261702d617373657274696f6e733f636f6c6f723d73756363657373) [![](https://camo.githubusercontent.com/89c28e81696b30ee96374d3c9282c10cd8d03e618e5e3ed99f168f7408c600cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73)](https://camo.githubusercontent.com/89c28e81696b30ee96374d3c9282c10cd8d03e618e5e3ed99f168f7408c600cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73) [![](https://camo.githubusercontent.com/af3f28a78fe92e086ebaa85f719197692e4ea230750ef83ec4507e7f0159ab96/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73)](https://camo.githubusercontent.com/af3f28a78fe92e086ebaa85f719197692e4ea230750ef83ec4507e7f0159ab96/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f4a542d50726f64756374696f6e732f6d61696c747261702d617373657274696f6e73)

The mailtrap assertiosn is to TDD your Laravel Application to check if mails has been send to mailtrap.

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

[](#installation)

You can install the package using

```
composer require --dev jtproductions/mailtrap-assertions
```

### .env file

[](#env-file)

You need to add a few variables into your `.env` file. You need to firstly login to your mailtrap.io account.

`MAILTRAP_API_KEY` =&gt; In the left navigation bar you click on API. There you see your API Token which you copy and paste in your .env file

`MAILTRAP_INBOX_ID` =&gt; In the left navigation bar you click on inboxes and then click on the name of your inbox. Now you see in the address bar something like . The number between inboxes and messages is your inbox ID. In this case it is `123456789`.

### tests/TestCase.php

[](#teststestcasephp)

In your tests directory you open up TestCase.php and add make sure you have the following code

```
protected function setUpTraits()
{
    $uses = parent::setUpTraits(); // TODO: Change the autogenerated stub

    if (isset($uses[RefreshMailtrap::class])) {
        $this->refreshMailtrap();
    }

    if (isset($uses[MailtrapAssertions::class])) {
        $this->mailtrapSetup();
    }
}
```

### phpunit.xml

[](#phpunitxml)

Open up your `phpunit.xml` file. Change `MAIL_MAILER` from `array` to `smtp`

Usage
-----

[](#usage)

### Adding traits

[](#adding-traits)

The trait RefreshMailtrap will empty you mailbox on each

```
class ExampleTest extends TestCase
{
    use RefreshMailtrap;
}
```

All the assertions are in the MailtrapAssertions Trait

```
class ExampleTest extends TestCase
{
    use MailtrapAssertions;
}
```

### Assert empty mailbox

[](#assert-empty-mailbox)

To check if the mailbox is empty

```
$this->assertMailboxEmpty();
```

### Assert mailbox has $count messages

[](#assert-mailbox-has-count-messages)

This asserts that there are 3 messages in the mailbox

```
$this->assertMailboxCount(3);
```

### Manual clean mailbox

[](#manual-clean-mailbox)

If you don't want to use the RefreshMailtrap trait or during a test clean your mailbox

```
$this->emptyMailbox();
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

1955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e97922b90ddfb703525b7da1e53674821999206dda963581d8322d8bc1a00f7?d=identicon)[jthijs](/maintainers/jthijs)

---

Top Contributors

[![JurgenThijs](https://avatars.githubusercontent.com/u/25119092?v=4)](https://github.com/JurgenThijs "JurgenThijs (6 commits)")

---

Tags

phpunitmailtrap

### Embed Badge

![Health badge](/badges/jtproductions-mailtrap-assertions/health.svg)

```
[![Health](https://phpackages.com/badges/jtproductions-mailtrap-assertions/health.svg)](https://phpackages.com/packages/jtproductions-mailtrap-assertions)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78137.2M122](/packages/johnkary-phpunit-speedtrap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

56426.3M456](/packages/dg-bypass-finals)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19254.9M1.4k](/packages/phpspec-prophecy-phpunit)

PHPackages © 2026

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