Provides test helpers for Codeception to facilitate email testing with Mailpit. This module allows you to search for and retrieve email content from Mailpit during your tests, making it easy to verify email functionality, extract activation keys, and more.
The Mailpit module integrates with Codeception using Guzzle to interact with Mailpit’s API. It provides methods to:
- Search Emails: Retrieve the most recent email(s) based on search criteria.
- Fetch Full Email Content: After searching, fetch the complete content of an email by its ID.
- Extract Information: Easily extract details such as activation keys for further assertions in your tests.
- Email Assertions for Codeception:
Install the module via Composer:
composer require dev trevorbicewebdesign/codeception-mailpit
Add the module to your Codeception suite configuration (for example, in your acceptance.suite.yml):
modules:
enabled:
- Mailpit
config:
Mailpit:
base_uri: 'http://localhost:10006'
- base_uri: The base URL for your Mailpit installation.
Once installed and configured, you can use the module in your tests. For example:
getLastEmailId()
- Get the mailpit message id of the most recent email.getEmailById($id)
- Retrieves an email by its ID.getEmailBySubject($subject)
- Retrieves the ID of the most recent email that matches the given subject.
- assertEmailTextContains($messageId, $expectedText)
- assertEmailTextEquals($messageId, $extectedText)
- assertEmailSubjectEquals($messageId, $expectedSubject)
- assertEmailSubjectContains($messageId, $expectedSubject)
- assertEmailHasHeaders($messageId,$expectedHeaders)