2017 © Pedro Peláez
 

library mailcatcher

A library to access MailCatcher

image

alexandresalome/mailcatcher

A library to access MailCatcher

  • Tuesday, July 24, 2018
  • by alexandresalome
  • Repository
  • 4 Watchers
  • 111 Stars
  • 292,665 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 28 Forks
  • 8 Open issues
  • 11 Versions
  • 9 % Grown

The README.md

MailCatcher for PHP

Build status Latest Stable Version Total Downloads License Monthly Downloads Daily Downloads, (*1)

Integrates MailCatcher in your PHP application., (*2)

MailCatcher is a simple SMTP server with an HTTP API, and this library aims to integrate it to make it easy to use it with PHP., (*3)

Behat extension

This library provides a Behat extension to help you test mails in your application., (*4)

To use it, you first need to be sure MailCatcher is properly installed and running. You can use docker to execute it:, (*5)

docker run -d -p 1080:1080 -p 1025:1025 --name mailcatcher schickling/mailcatcher

First, configure in your behat.yml:, (*6)

default:
    extensions:
        Alex\MailCatcher\Behat\MailCatcherExtension\Extension:
            url: http://localhost:1080
            purge_before_scenario: true

Then, add the MailCatcherContext context in your FeatureContext file:, (*7)

use Alex\MailCatcher\Behat\MailCatcherContext;
use Behat\Behat\Context\BehatContext;

class FeatureContext extends BehatContext
{
   public function __construct(array $parameters)
   {
      $this->useContext('mailcatcher', new MailCatcherContext());
   }
}

Available steps

This extension provides you mail context in your tests. To use assertions, you must first open a mail using criterias., (*8)

Once it's opened, you can make assertions on it and click in it., (*9)

Server manipulation, (*10)

Deletes all messages on the server, (*11)

  • When I purge mails

Mail opening, (*12)

  • When I open mail from "foo@example.org"
  • When I open mail containing "a message"
  • When I open mail to "me@example.org"
  • When I open mail with subject "Welcome, mister Bond!"

Assertion, (*13)

Verify number of messages sent to the server:, (*14)

  • Then 1 mail should be sent
  • Then 13 mails should be sent

Verify text presence in message:, (*15)

  • Then I should see "something" in mail
  • Then I should see "something else" in mail

Verify text presence in mail without opening:, (*16)

  • Then I should see mail from "foo@example.org"
  • Then I should see mail containing "a message"
  • Then I should see mail to "me@example.org"
  • Then I should see mail with subject "Welcome, mister Bond!"

Custom mailcatcher context

Only available from PHP 5.4, (*17)

If you want to create a context class that relates to MailCatcher, you can use the MailCatcherTrait to get the mailcatcher client injected inside your class:, (*18)

use Alex\MailCatcher\Behat\MailCatcherAwareInterface;
use Alex\MailCatcher\Behat\MailCatcherTrait;
use Alex\MailCatcher\Message;
use Behat\Behat\Context\Context;

class WelcomeContext implements Context, MailCatcherAwareInterface
{
    use MailCatcherTrait;

    /**
     * @Then /^a welcome mail should be sent$/
     */
    public function testTrait()
    {
        $this->findMail(Message::SUBJECT_CRITERIA, 'Welcome!');
    }
}

This trait offers the following methods:, (*19)

  • getMailCatcherClient(): returns the mailcatcher Client instance.
  • findMail($criteria, $value): facility to search for a given message, or throws an exception if not found

Don't forget to implement the MailCatcherAwareInterface to get the mailcatcher client injected inside your context class., (*20)

Client API

Browse easily your API with the integrated SDK:, (*21)

$client = new Alex\MailCatcher\Client('http://localhost:1080');

// Returns all messages
$messages = $client->search();

// Count messages
$client->getMessageCount();

// Filter messages
$messages = $client->search(array(
    'from'        => 'bob@example.org',
    'to'          => 'alice@example.org',
    'subject'     => 'Bla',
    'contains'    => 'Hello',
    'attachments' => true,
    'format'      => 'html',
), $limit = 3);

// Search one message
$message = $client->searchOne(array('subject' => 'Welcome'));

Message API, (*22)

// Message API, get the content of a message
$subject = $message->getSubject();
$plainTextBody = $message->getPart('text/plain')->getContent();
$htmlBody = $message->getPart('text/html')->getContent();

// Message API, return a Person object or an array of Person object
$person  = $message->getFrom();
$persons = $message->getRecipients();

// Person API
$person = $message->getFrom();

$name = $person->getName(); // null means not provided
$mail = $person->getMail();

// Attachments
$message->hasAttachments();
$message->getAttachments();

// Delete
$message->delete();

Attachment API, (*23)

// Attachment API
$attachment->getFilename();
$attachment->getSize();
$attachment->getType();
$attachment->getContent();

The Versions

24/07 2018

dev-master

9999999-dev

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

24/05 2018

v1.2.1

1.2.1.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

08/07 2016

v1.2.0

1.2.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

17/03 2016

v1.1.1

1.1.1.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

18/01 2016

v1.1.0

1.1.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2015

v1.0.2

1.0.2.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

06/07 2015

v1.0.0

1.0.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

06/07 2015

v1.0.1

1.0.1.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

19/01 2015

v0.3.0

0.3.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

08/10 2013

v0.2.0

0.2.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

09/07 2013

v0.1

0.1.0.0

A library to access MailCatcher

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires