I've wrapped this helper up as a module which means it can be installed using Composer which makes more sense. Plese use the module instead:
Codeception MailCatcher Module
This helper will let you test emails that are sent during your Codeception acceptance tests. It depends upon you having MailCatcher installed on your development server. I have it installed as part of my development virtual machine.
It was inspired by the Codeception blog post: Testing Email in PHP. It is currently very simple. Send a pull request or file an issue if you have ideas for more features.
First you need to download the helper into your _helpers
directory:
$ cd path/to/your/tests/_helpers/
$ wget https://raw.githubusercontent.com/captbaritone/mailcatcher-codeception-helper/master/MailCatcherHelper.php
Then enable it in your acceptance.suite.yml
configuration and set the url and
port of your site's MailCatcher installation:
class_name: WebGuy
modules:
enabled:
- MailCatcherHelper
config:
MailCatcherHelper:
url: 'http://project.dev'
port: '1080'
<?php
$I = new WebGuy\AdminSteps($scenario);
$I->wantTo('Get a password reset email');
// Cleared old emails from MailCatcher
$I->resetEmails();
// Reset
$I->amOnPage('forgotPassword.php');
$I->fillField("input[name='email']", '[email protected]');
$I->click("Submit");
$I->see("Please check your email");
$I->seeInLastEmail("Please click this link to reset your password");
Clears the emails in MailCatcher's list. This is prevents seeing emails sent during a previous test. You probably want to do this before you trigger any emails to be sent
Example:
<?php
// Clears all emails
$I->resetEmails();
?>
Checks that an email contains a value. It searches the full raw text of the email: headers, subject line, and body.
Example:
<?php
$I->seeInLastEmail('Thanks for signing up!');
?>
Checks that the last email sent to an address contains a value. It searches the full raw text of the email: headers, subject line, and body.
This is useful if, for example a page triggers both an email to the new user, and to the administrator.
Example:
<?php
$I->seeInLastEmailTo('[email protected]', 'Thanks for signing up!');
$I->seeInLastEmailTo('[email protected]', 'A new user has signed up!');
?>
Released under the same liceces as Codeception: MIT