Download the PHP package rpkamp/mailhog-behat-extension without Composer

On this page you can find all versions of the php package rpkamp/mailhog-behat-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mailhog-behat-extension

Mailhog Behat Extension Packagist Version

A simple PHP (8.1+) Behat extension for Mailhog.

Installation

This package does not require any specific HTTP client implementation, but it requires rpkamp/mailhog-client, which is based on HTTPlug, so you can inject your own HTTP client of choice. So you when you install this extension make sure you either already have an HTTP client installed, or install one at the same time as installing this extension, otherwise installation will fail.

For more information please refer to the HTTPlug documentation for Library Users.

Usage

Register extension in Behat

Add the extension to your behat.yml like so:

The base_url is the URL where the Mailhog Web UI is listening to (by default this is http://localhost:8025). Thepurge_tag` is the behat tag that triggers a purge in mailhog before the scenario/feature (see "Use email tag to purge emails before scenarios")

Use MailhogContext

The easiest way to get started is to configure behat to use rpkamp\Behat\MailhogExtension\Context\MailhogContext like so:

This enables the following Gherkin for your scenarios to make assumptions on received email messages:

Alternatively you can "open" an email an run assumptions on the opened email:

Take care that the implementation of this currently isn't very efficient. If there are a lot of emails in Mailhog it might take a while, especially when the email you're looking for is not there.

Implement MailhogAwareContext

If you want to implement something more advanced than rpkamp\Behat\MailhogExtension\Context\MailhogContext offers you can also implement rpkamp\Behat\MailhogExtension\Context\MailhogAwareContext in your own context and implement the method in that interface:

Now every time your FeatureContext is initialized Behat will inject an rpkamp\MailhogClient in it you can use using the $mailhog property of your context. For example:

Use email tag to purge emails before scenarios

In scenarios where you want to make sure you have received the correct number of messages you will want to purge mailhog before the scenario is started. In order to do that add the @email tag to either the scenario or the feature. As usual, when you apply it to the feature it applies to all scenarios within that feature.

If you want to use a different tag you can supply the name (without the initial @) in the purge_tag setting of this extension.

Implement OpenedEmailStorageAwareContext (Advanced)

If you want to write an extension/context for behat that uses the feature of opening email from this extension you can have your Context implement OpenedEmailStorageAwareContext:

Run tests

Make sure you have Mailhog running and run:

Running Mailhog for tests

You can either run your own instance of Mailhog or use the provided docker-compose file to run one for you. To run Mailhog with Docker make sure you have Docker and docker-compose installed and run:

Mailhog ports for tests

To prevent port collisions with any other Mailhog instances while testing the tests expect Mailhog to listen to SMTP on port 3025 (instead of the default 1025) and to HTTP traffic on port 10025 (instead of the default 8025).


All versions of mailhog-behat-extension with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
behat/behat Version ^3.8.0
rpkamp/mailhog-client Version ^2.0
symfony/dependency-injection Version ^6.4 || ^7.0
psr-discovery/http-client-implementations Version ^1.0
psr-discovery/http-factory-implementations Version ^1.0
symfony/http-client Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rpkamp/mailhog-behat-extension contains the following files

Loading the files please wait ....