rezouce/codeception-mailcatcher

允许使用 Mailcatcher 与 Codeception 一起使用

1.1.0 2016-02-01 14:21 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:10:46 UTC


README

这是一个 Codeception 模块,用于测试您应用程序发送的电子邮件,使用 MailCatcher。

安装

要将它添加到您的项目中,运行 composer require rezouce/codeception-mailcatcher

然后您可以将 MailCatcher 添加到 Codeception 配置文件中已启用的模块部分

modules:
    enabled:
        - MailCatcher

默认情况下,该模块将尝试在 http://127.0.0.1:1080 上联系 MailCatcher,您可以使用配置进行更改

modules:
    enabled:
        - MailCatcher
    config:
        MailCatcher:
            url: 'http://127.0.0.1'
            port: '1080'

使用方法

断言

<?php
// Check if there is at least an email
$this->hasEmails();

// Count the number of mails
$this->seeNumberEmails(5);

// Check if at least an email contains a string in its source
$this->seeInEmail('A string.');

获取电子邮件

<?php
$emails = $this->getEmailsBySubject('subject');
$emails = $this->getEmailsBySender('user@example.com');
$emails = $this->getEmailsByRecipients(['user1@example.com']);

默认情况下,这些方法中的每一个都会在属性包含搜索条件时检索电子邮件。您可以通过将布尔值作为第二个参数并设置值为 true 来改为严格检查。

您还可以对所获取的电子邮件进行断言

<?php
$emails = $this->getEmailsBySubject('subject');
$this->hasEmails($emails);

许可证

这个库是开源软件,许可协议为 MIT 协议