PHP code example of koehnlein / codeception-email-mailpit

1. Go to this page and download the library: Download koehnlein/codeception-email-mailpit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

koehnlein / codeception-email-mailpit example snippets


deleteAllEmails()

fetchEmails()

accessInboxFor($address)

openNextUnreadEmail()

openNextAttachmentInOpenedEmail()


$I = new FunctionalTester($scenario);
$I->am('a member');
$I->wantTo('request a reset password link');

// First, remove all existing emails in the Mailpit inbox
$I->deleteAllEmails();

// Implementation is up to the user, use this as an example
$I->requestAPasswordResetLink();

// Query Mailpit and fetch all available emails
$I->fetchEmails();

// This is optional, but will filter the emails in case you're sending multiple emails or use the BCC field
$I->accessInboxFor('[email protected]');

// A new email should be available and it should be unread
$I->haveEmails();
$I->haveUnreadEmails();

// Set the next unread email as the email to perform operations on
$I->openNextUnreadEmail();

// After opening the only available email, the unread inbox should be empty
$I->dontHaveUnreadEmails();

// Validate the content of the opened email, all of these operations are performed on the same email
$I->seeInOpenedEmailSubject('Your Password Reset Link');
$I->seeInOpenedEmailTextBody('Follow this link to reset your password');
$I->seeInOpenedEmailHtmlBody('<a href="https://www.example.org/">Follow this link to reset your password</a>');
$I->seeInOpenedEmailRecipients('[email protected]');

// Validate if email has attachments
$I->haveAttachmentsInOpenedEmail();

// Open next attachment
$I->openNextAttachmentInOpenedEmail();

// Validate metadata of the attachment
$I->seeInFilenameOfOpenedAttachment();
$I->grabFilenameFromOpenedAttachment();
$I->grabContentTypeFromOpenedAttachment();
$I->grabSizeFromOpenedAttachment();