Skip to content

pmaasz/BehatMailExtension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Behat Mail Extension

Supported Drivers

Installation

{
     "require": {
            "pmaasz/behat-mail-extension": "dev-master"
        },
    
    "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/pmaasz/BehatMailExtension.git"
            }
        ]
}

Configure Your Context

  1. Implement the MailAwareContext in your feature context

  2. Use the MailTrait in your context.

use BehatMailExtension\Context\MailAwareContext;
use BehatMailExtension\Context\MailTrait;

class FeatureContext implements MailAwareContext 
{
    use MailTrait;
    
    ...

Using the mail trait will add a mail property to your feature context.

behat.yml

IMAP

Add the MailExtension to your behat.yaml file:

default:
    extensions:
        BehatMailExtension\ServiceContainer\MailExtension:
            driver: imap //required
            server: 'imap.gmail.com' //required
            port: //defaults to '993' //required
            flags: //defaults to '/imap/ssl/validate-cert' //required 
            username: //required
            password: //required

Usage

Access the mail property from your feature context to test any emails sent.

    /**
     * @Then I should receive a welcome email
     */
    public function iShouldReceiveAWelcomeEmail()
    {
        $message = $this->mail->getMessages();

        PHPUnit_Framework_Assert::assertEquals('Welcome!', $message->getSubject());
        PHPUnit_Framework_Assert::assertContains('Please confirm your account', $message->getBodyText());
    }

The IMAP Driver API

The mail driver, accessible via the mail property on the feature context, offers the following methods. These methods are described in the MailDriverInterface.

  • getMailbox()
  • getMailboxes()
  • analyzeMailbox()
  • analyzeMailboxes()
  • setMailboxFlag()
  • getMessages()
  • sendMessage()
  • sendMessages()
  • searchMessages()
  • moveMessage()
  • downloadMessageAttachments()
  • deleteMessage()
  • deleteMessages() (This is called automatically after scenarios tagged @mail)

The Message API

The mail driver will return a message object with the following API:

  • getTo()
  • getFrom()
  • getDate() (DateTimeImmutable)
  • getSubject()
  • isAnswered()
  • isDeleted()
  • isDraft()
  • isSeen()
  • getBodyHtml()
  • getBodyText()
  • markAsSeen()
  • setFlag()
  • clearFlag()
  • getAttachements()

Star History

Star History Chart

Releases

No releases published

Packages

No packages published

Languages