2017 © Pedro Peláez
 

library mailcatcher-codeception-module

Test emails in your Codeception acceptance tests

image

captbaritone/mailcatcher-codeception-module

Test emails in your Codeception acceptance tests

  • Sunday, July 1, 2018
  • by captbaritone
  • Repository
  • 7 Watchers
  • 80 Stars
  • 382,651 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 27 Forks
  • 9 Open issues
  • 12 Versions
  • 8 % Grown

The README.md

Codeception MailCatcher Module

Build Status, (*1)

This module will let you test emails that are sent during your Codeception acceptance tests. It depends upon you having MailCatcher installed on your development server., (*2)

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

Installation

  1. Add the package to your composer.json:, (*4)

    composer require --dev captbaritone/mailcatcher-codeception-module, (*5)

  2. Configure your project to actually send emails through smtp://127.0.0.1:1025 in the test environment, (*6)

  3. Enable the module in your acceptance.suite.yml:, (*7)

    modules:
        enabled:
            - MailCatcher
        config:
            MailCatcher:
                url: 'http://127.0.0.1'
                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:, (*8)

class_name: WebGuy
modules:
    enabled:
        - MailCatcher
    config:
        MailCatcher:
            url: 'http://127.0.0.1'
            port: '1080'
            guzzleRequestOptions:
                verify: false
                debug: true
                version: 1.0

Example Usage

```php wantTo('Get a password reset email'); // Clear old emails from MailCatcher $I->resetEmails(); // Reset password $I->amOnPage('forgotPassword.php'); $I->fillField("input[name='email']", 'user@example.com'); $I->click('Submit'); $I->see('Please check your inbox'); $I->seeInLastEmail('Please click this link to reset your password'); ``` ## Actions ### resetEmails Clears the emails in MailCatcher's list. This prevents seeing emails sent during a previous test. You probably want to do this before you trigger any emails to be sent Example: resetEmails(); ?>, (*9)

seeEmailAttachmentCount

Checks expected count of attachments in last email., (*10)

Example:, (*11)

<?php
$I->seeEmailAttachmentCount(1);
?>
  • Param $expectCount

seeAttachmentInLastEmail

Checks that last email contains an attachment with filename., (*12)

Example:, (*13)

<?php
$I->seeAttachmentInLastEmail('image.jpg');
?>
  • Param $filename

seeInLastEmail

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

Example:, (*15)

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

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

Example:, (*18)

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

Example:, (*20)

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

Example:, (*22)

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

grabAttachmentsFromLastEmail

Grab Attachments From Email, (*23)

Returns array with the format [ [filename1 => bytes1], [filename2 => bytes2], ...], (*24)

Example:, (*25)

<?php
$attachments = $I->grabAttachmentsFromLastEmail();
?>

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

Example:, (*27)

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

Example:, (*29)

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

grabUrlsFromLastEmail

Extracts an array of urls from the last email. It searches the full raw body of the email. The return value is an array of strings., (*30)

Example:, (*31)

<?php
$urls = $I->grabUrlsFromLastEmail();
?>

lastMessageFrom

Grab the full email object sent to an address., (*32)

Example:, (*33)

<?php
$email = $I->lastMessageFrom('example@example.com');
$I->assertNotEmpty($email['attachments']);
?>

lastMessage

Grab the full email object from the last email., (*34)

Example:, (*35)

<?php
$email = $I->grabLastEmail();
$I->assertNotEmpty($email['attachments']);
?>

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

Example:, (*37)

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

Example:, (*39)

<?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 resetEmails() was called., (*40)

Example:, (*41)

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

License

Released under the same license as Codeception: MIT, (*42)

The Versions

01/07 2018

dev-master

9999999-dev

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

The Development Requires

01/07 2018

2.0.0

2.0.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

The Development Requires

06/09 2016

dev-fix-guzzle-options

dev-fix-guzzle-options

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

16/08 2016

1.2.1

1.2.1.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

07/06 2016

dev-version-up

dev-version-up

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

07/06 2016

1.2.0

1.2.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

07/06 2016

dev-ruby

dev-ruby

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

27/08 2015

3.x-dev

3.9999999.9999999.9999999-dev

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

27/08 2015

dev-codeception-v3

dev-codeception-v3

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

27/08 2015

1.1.1

1.1.1.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

04/04 2015

1.1.0

1.1.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires

 

11/07 2014

1.0.0

1.0.0.0

Test emails in your Codeception acceptance tests

  Sources   Download

The Requires