定制 dmoen/mailtrap-test-helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dmoen/mailtrap-test-helper

Composer 安装命令:

composer require dmoen/mailtrap-test-helper

包简介

Test helper library for testing email submissions through Mailtrap, based on PHPUnit

README 文档

README

Test helper library for testing email submissions through Mailtrap, based on PHPUnit.

Installation

This package can be installed via Composer:

composer require dmoen/mailtrap-test-helper --dev

Usage

Create an instance of MailTrapInbox with api key and id of the inbox:

$inbox = new MailTrapInbox('api_key', 'inbox_id');  

Example using a PHPUnit test case. Before each test the inbox should be cleaned:

private $inbox;

public function setUp()
{
    parent::setUp();

    $this->inbox = new MailTrapInbox('api_key', 'inbox_id'));
    $this->inbox->deleteAllMessages();
}

Simple inbox testing

Test if the inbox has any messages:

$inbox->assertHasMails();  

Test if the inbox has any messages from a specific address:

$inbox->assertHasMailFrom("sender@example.com");

With name:

$inbox->assertHasMailFrom("sender@example.com", "Sender Sendersson");

Test if the inbox has any messages to a specific address:

$inbox->assertHasMailFor("reciever@example.com");

With name:

$inbox->assertHasMailFor("reciever@example.com", "Receiver Receiversson");

Test if inbox has a message with a subject:

$inbox->assertHasMailWithSubject('Lorem subject');

Test if inbox has a message with a specific body:

$inbox->assertHasMailWithHtmlContent('<b>Lorem ipsum sit amet</b>');
$inbox->assertHasMailWithTextContent('Lorem ipsum sit amet');

A bit more advanced testing for specific emails

To retrieve a specific message in the inbox:

$inbox->getLastMessage()
$inbox->getFirstMessage()

Or if you know the specific index in the inbox:

$message = $inbox->getMessage(2);

You can also search the inbox for a specific unique message using a condition:

$message = $inbox->findUnique(function($message){
    return $message->to_email == "receiver@example.com";
});

Or retrieve an array of all messages or by condition:

$messages = $inbox->fetchAllMessages();
$messages = $inbox->findMessages(function($message){
    return $message->to_email == "receiver@example.com";
});

The message instance passed to the closure has all the properties retrieved from the Mailtrap API: http://docs.mailtrap.apiary.io/#reference/message/apiv1inboxesinboxidmessagesid/get

The message(s) can then be tested with a combination of tests:

$message->assertIsFrom("me@railsware.com", "Private Person")
    ->assertIsFor("test@railsware.com", "A Test User")
    ->assertHasSubject("SMTP e-mail test")
    ->assertHasTextContent("This is a test e-mail message")
    ->assertHasHtmlContent("<b>Lorem ipsum sit amet.</b>");

dmoen/mailtrap-test-helper 适用场景与选型建议

dmoen/mailtrap-test-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dmoen/mailtrap-test-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dmoen/mailtrap-test-helper 我们能提供哪些服务?
定制开发 / 二次开发

基于 dmoen/mailtrap-test-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-06