2017 © Pedro Peláez
 

library codeception-mailchecker-module

Test emails in your Codeception acceptance tests

image

johnatannvmd/codeception-mailchecker-module

Test emails in your Codeception acceptance tests

  • Sunday, February 19, 2017
  • by johnatannvmd
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,274 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 35 % Grown

The README.md

Codeception MailChecker Module

This repo is abandoned. Please use https://github.com/captbaritone/codeception-mailcatcher-module instead or any other similar project., (*1)

Build Status Coverage Status, (*2)

This module will let you test emails that are sent during your Codeception acceptance tests., (*3)

It was inspired by the https://github.com/captbaritone/codeception-mailcatcher-module and https://github.com/fetch/zend-mail-codeception-module/., (*4)

It supports several mail testing tools:, (*5)

Installation

Add the packages into your composer.json. For example we add Guzzle lib for MailCatcher for MailDump provider:, (*6)

{
    "require-dev": {
        "codeception/codeception": "*",
        "johnatannvmd/mailchecker-codeception-module": "1.*"
    }
} 

Tell Composer to download the package:, (*7)

php composer.phar update

Then enable it in your acceptance.suite.yml configuration and set the url and port of your site's MailCatcher installation:, (*8)

class_name: WebGuy
modules:
    enabled:
        - MailChecker
    config:
        MailChecker:
            provider: MailCatcher
            options:
                url: 'http://project.dev'
                port: '1080'

Optional Configuration

If you need to specify some special options (e.g. SSL verification or authentication headers), you can set all of the allowed Guzzle request options:, (*9)

class_name: WebGuy
modules:
    enabled:
        - MailChecker
    config:
        MailChecker:
            provider: MailDump
            options:
                url: 'http://project.dev'
                port: '1080'
                guzzleOptions:
                    auth: ['yo', 'yo']

Example Usage

<?php

$I = new WebGuy($scenario);
$I->wantTo('Get a password reset email');

// Cleared old emails from MailCatcher
$I->clearMailbox();

// Reset 
$I->amOnPage('forgotPassword.php');
$I->fillField("input[name='email']", 'user@example.com');
$I->click("Submit");
$I->see("Please check your email");

$I->seeInLastEmail("Please click this link to reset your password");

Actions

clearMailbox

Clears the emails in providers'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, (*10)

Example:, (*11)

<?php
// Clears all emails
$I->clearMailbox();
?>

seeInLastEmail

Checks that an email contains a value. It searches the full raw text of the email: headers, subject line, and body., (*12)

Example:, (*13)

<?php
$I->seeInLastEmail('Thanks for signing up!');
?>
  • Param $text

seeInLastEmailTo

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., (*14)

This is useful if, for example a page triggers both an email to the new user, and to the administrator., (*15)

Example:, (*16)

<?php
$I->seeInLastEmailTo('user@example.com', 'Thanks for signing up!');
$I->seeInLastEmailTo('admin@example.com', 'A new user has signed up!');
?>
  • Param $email
  • Param $text

dontSeeInLastEmail

Checks that an email does NOT contain a value. It searches the full raw text of the email: headers, subject line, and body., (*17)

Example:, (*18)

<?php
$I->dontSeeInLastEmail('Hit me with those laser beams');
?>
  • Param $text

dontSeeInLastEmailTo

Checks that the last email sent to an address does NOT contain a value. It searches the full raw text of the email: headers, subject line, and body., (*19)

Example:, (*20)

<?php
$I->dontSeeInLastEmailTo('admin@example.com', 'But shoot it in the right direction');
?>
  • Param $email
  • Param $text

seeAttachmentFilenameInLastEmail

Checks that the last email have attachment with following filename., (*21)

Example:, (*22)

<?php
$I->seeAttachmentFilenameInLastEmail('expected_journey.ext');
?>
  • Param $expectedFilename

dontSeeAttachmentFilenameInLastEmail)

Checks that the last email does NOT have attachment with following filename., (*23)

Example:, (*24)

<?php
$I->dontSeeAttachmentFilenameInLastEmail('unexpected_journey.ext');
?>
  • Param $unexpectedFilename

seeAttachmentFilenameInLastEmailTo

Checks that the last sent to an address have attachment with following filename., (*25)

Example:, (*26)

<?php
$I->seeAttachmentFilenameInLastEmailTo('admin@example.com', 'expected_journey.ext');
?>
  • Param $address
  • Param $expectedFilename

dontSeeAttachmentFilenameInLastEmailTo

Checks that the last sent to an address does NOT have attachment with following filename., (*27)

Example:, (*28)

<?php
$I->dontSeeAttachmentFilenameInLastEmailTo('admin@example.com', 'unexpected_journey.ext');
?>
  • Param $address
  • Param $unexpectedFilename

seeAttachmentsCountInLastEmail

Asserts that a certain number of attachments found in the last email., (*29)

Example:, (*30)

<?php
$I->seeAttachmentsCountInLastEmail(1);
?>
  • Param $exected

seeAttachmentsCountInLastEmailTo

Asserts that a certain number of attachments found in the last email to a given address., (*31)

Example:, (*32)

<?php
$I->seeAttachmentsCountInLastEmailTo('admin@example.com', 1);
?>
  • Param $address
  • Param $expected

seeCcInLastEmail

Look for the expected CC address in the last sent email., (*33)

Example:, (*34)

<?php
$I->seeCcInLastEmail('cc@example.com');
?>
  • Param $expectedAddress

seeCcInLastEmailTo

Look for the expected CC address in the last sent email to a given address., (*35)

Example:, (*36)

<?php
$I->seeCcInLastEmailTo('admin@example.com', 'cc@example.com');
?>
  • Param $address
  • Param $expectedAddress

grabMatchesFromLastEmail

Extracts an array of matches and sub-matches from the last email based on a regular expression. It searches the full raw text of the email: headers, subject line, and body. The return value is an array like that returned by preg_match()., (*37)

Example:, (*38)

<?php
$matches = $I->grabMatchesFromLastEmail('@<strong>(.*)</strong>@');
?>
  • Param $regex

grabFromLastEmail

Extracts a string from the last email based on a regular expression. It searches the full raw text of the email: headers, subject line, and body., (*39)

Example:, (*40)

<?php
$match = $I->grabFromLastEmail('@<strong>(.*)</strong>@');
?>
  • Param $regex

grabMatchesFromLastEmailTo

Extracts an array of matches and sub-matches from the last email to a given address based on a regular expression. It searches the full raw text of the email: headers, subject line, and body. The return value is an array like that returned by preg_match()., (*41)

Example:, (*42)

<?php
$matchs = $I->grabMatchesFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
?>
  • Param $email
  • Param $regex

grabFromLastEmailTo

Extracts a string from the last email to a given address based on a regular expression. It searches the full raw text of the email: headers, subject line, and body., (*43)

Example:, (*44)

<?php
$match = $I->grabFromLastEmailTo('user@example.com', '@<strong>(.*)</strong>@');
?>
  • Param $email
  • Param $regex

seeEmailCount

Asserts that a certain number of emails have been sent since the last time clearMailbox() was called., (*45)

Example:, (*46)

<?php
$match = $I->seeEmailCount(2);
?>
  • Param $count

Docker

Now you can build all modules at once by:, (*47)

docker-compose build

License

Released under the same licence as Codeception: MIT, (*48)

The Versions

19/02 2017

dev-master

9999999-dev

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

19/02 2017

1.4

1.4.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

27/07 2016

1.3

1.3.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

06/03 2016

1.2.1

1.2.1.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

05/03 2016

1.2

1.2.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

28/12 2015

1.1

1.1.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Evgeniy Tetenchuk

mail test mailcatcher codeception acceptance mailtrap maildump lathermail

23/12 2015

1.0

1.0.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Evgeniy Tetenchuk

mail test codeception acceptance