A PHPUnit extension for testing emails via the Mailinator API
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
LICENSE
README.md
composer.json

README.md

MahanaMailinatorTest

Software License

A PHPUnit extension for testing emails via the Mailinator API

Requirements

You need to have the cURL-extension installed on your server. PHP 5.4 will suffice.

Mahana Mailinator Test depends on the Mahana Mailinator API library (will install with composer, or can be found here: https://github.com/jrmadsen67/MahanaMailinatorAPI)

Installation

composer require jrmadsen67/mahana-mailinator-test

Usage

Mahana Mailinator Test is a PHPUnit extension used for functional email testing against the Mailintor API. You will need to get an api token at https://www.mailinator.com/settings.jsp.

In your tests, create a Mahana Mailinator API object with your token, then pass that object to your Mahana Mailinator Test object:

use jrmadsen67\MahanaMailinatorAPI\MahanaMailinatorAPI;
use jrmadsen67\MahanaMailinatorAPI\MahanaMailinatorTest;

$mahanaMailinatorAPI = new MahanaMailinatorAPI($token);
$mahanaMailinatorTest = new MahanaMailinatorTest($mahanaMailinatorAPI);

IMPORTANT! You need to send emails via your own mail library. This library will only retreive and test the contents.

Examples:

// inbox value does not require "@mailinator.com" for the API to retrieve.
$inbox = 'mytestbox@mailinator.com';  

//psuedo-code to send an email:
mail_send([
    'to'=>$inbox, 
    'subject' => 'My test subject', 
    'from'=> 'me@test.com', 
    'body' => 'blah, blah, blah', 
]);


// get the email you just sent. this is an array.
$email = $mahanaMailinatorTest->getLastMessage($inbox); 

//start testing
$mahanaMailinatorTest->assertEmailSubjectContains('test', $email);
$mahanaMailinatorTest->assertEmailSubjectEquals('My test subject', $email);
$mahanaMailinatorTest->assertEmailTextContains('blah', $email);

Please read the library source for a full set of functions. (Better specs on the way, I promise!)