承接 kirschbaum-development/mail-intercept 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kirschbaum-development/mail-intercept

Composer 安装命令:

composer require kirschbaum-development/mail-intercept

包简介

A test package for intercepting email sent from Laravel

README 文档

README

Mail Intercept banner

Laravel Mail Intercept

A testing package for intercepting mail sent from Laravel

Latest Version on Packagist Total Downloads Codacy Badge Actions Status

This testing suite intercepts Laravel Mail just before they are sent out, allowing all kinds of assertions to be made on the actual emails themselves.

Mail isn't faked here. You get to inspect the actual mail ensuring you are sending exactly what you want!

Requirements

Laravel Version Mail Intercept Version
10.x & 11.0 1.0.x
9.x 0.3.x
8.x and lower 0.2.x

Please note: If you are using v0.2.x, please refer to that version's documentation.

Installation

composer require kirschbaum-development/mail-intercept --dev

Usage

Next you can use the KirschbaumDevelopment\MailIntercept\WithMailInterceptor trait in your test class:

namespace Tests;

use App\Mail\TestMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Testing\WithFaker;
use KirschbaumDevelopment\MailIntercept\WithMailInterceptor;

class MailTest extends TestCase
{
    use WithFaker;
    use WithMailInterceptor;

    public function testMail()
    {
        $this->interceptMail();

        $email = $this->faker->email;

        Mail::to($email)->send(new TestMail());

        $interceptedMail = $this->interceptedMail()->first();

        $interceptedMail->assertSentTo($email);
    }
}

That's it! Pretty simple, right?!

There are two ways of accessing the assertions. First is the fluent syntax directly on each intercepted email.

$interceptedMail->assertSentTo($email);

The other way (the older way) is to use the assertions methods made available from the WithMailInterceptor trait. Using these methods are fine, but aren't as clean to write.

$this->assertMailSentTo($email, $interceptedEmail);

Both of these assertions do the exact same thing, the fluent one is just much cleaner. See all the available assertion methods below!

Testing API

$this->interceptMail()

This method MUST be called first, similar to how Mail::fake() works. But unlike the mail fake, mail is not faked, it is intercepted.

$this->interceptedMail()

This should be called after Mail has been sent, but before your assertions, otherwise you won't have any emails to work with. It returns a Collection of emails so you are free to use any of the methods available to a collection.

Fluent Assertion Methods

Assertions Parameters
$intercepted->assertSentTo($to); $to array, string
$intercepted->assertNotSentTo($to); $to array, string
$intercepted->assertSentFrom($from); $from array, string
$intercepted->assertNotSentFrom($from); $from array, string
$intercepted->assertSubject($subject); $subject string
$intercepted->assertNotSubject($subject); $subject string
$intercepted->assertBodyContainsString($content); $content string
$intercepted->assertBodyNotContainsString($content); $content string
$intercepted->assertRepliesTo($reply); $reply array, string
$intercepted->assertNotRepliesTo($reply); $reply array, string
$intercepted->assertCc($cc); $cc array, string
$intercepted->assertNotCc($cc); $cc array, string
$intercepted->assertBcc($cc); $bcc array, string
$intercepted->assertNotBcc($cc); $bcc array, string
$intercepted->assertSender($sender); $sender array, string
$intercepted->assertNotSender($sender); $sender array, string
$intercepted->assertReturnPath($returnPath); $returnPath string
$intercepted->assertNotReturnPath($returnPath); $returnPath string
Content Type Assertions
$intercepted->assertIsPlain();
$intercepted->assertIsNotPlain();
$intercepted->assertHasPlainContent();
$intercepted->assertDoesNotHavePlainContent();
$intercepted->assertIsHtml();
$intercepted->assertIsNotHtml();
$intercepted->assertHasHtmlContent();
$intercepted->assertDoesNotHaveHtmlContent();
$intercepted->assertIsAlternative();
$intercepted->assertIsNotAlternative();
$intercepted->assertIsMixed();
$intercepted->assertIsNotMixed();
Header Assertions Parameters
$intercepted->assertHasHeader($header); $header string
$intercepted->assertMissingHeader($header); $header string
$intercepted->assertHeaderIs($header, $value); $header string
$value string
$intercepted->assertHeaderIsNot($header, $value); $header string
$value string
Priority Assertions Parameters
$intercepted->assertPriority($priority); $priority int
$intercepted->assertNotPriority($priority); $priority int
$intercepted->assertPriorityIsHighest();
$intercepted->assertPriorityNotHighest();
$intercepted->assertPriorityIsHigh();
$intercepted->assertPriorityNotHigh();
$intercepted->assertPriorityIsNormal();
$intercepted->assertPriorityNotNormal();
$intercepted->assertPriorityIsLow();
$intercepted->assertPriorityNotLow();
$intercepted->assertPriorityIsLowest();
$intercepted->assertPriorityIsLowest();
Attachment Assertions Parameters
$intercepted->assertHasAttachment($filename); $filename string
$intercepted->assertHasAttachments();
$intercepted->assertMissingAttachment($filename); $filename string
$intercepted->assertMissingAttachments();
$intercepted->assertHasEmbeddedImage($filename); $filename string
$intercepted->assertHasEmbeddedImages();
$intercepted->assertMissingEmbeddedImage($filename); $filename string
$intercepted->assertMissingEmbeddedImages();

Assertion Methods

Assertions Parameters
$this->assertMailSentTo($to, $mail); $to array, string
$mail AssertableMessage, Email
$this->assertMailNotSentTo($to, $mail); $to array, string
$mail AssertableMessage, Email
$this->assertMailSentFrom($from, $mail); $from array, string
$mail AssertableMessage, Email
$this->assertMailNotSentFrom($from, $mail); $from array, string
$mail AssertableMessage, Email
$this->assertMailSubject($subject, $mail); $subject string
$mail AssertableMessage, Email
$this->assertMailNotSubject($subject, $mail); $subject string
$mail AssertableMessage, Email
$this->assertMailBodyContainsString($content, $mail); $content string
$mail AssertableMessage, Email
$this->assertMailBodyNotContainsString($content, $mail); $content string
$mail AssertableMessage, Email
$this->assertMailRepliesTo($reply, $mail); $reply array, string
$mail AssertableMessage, Email
$this->assertMailNotRepliesTo($reply, $mail); $reply array, string
$mail AssertableMessage, Email
$this->assertMailCc($cc, $mail); $cc array, string
$mail AssertableMessage, Email
$this->assertMailNotCc($cc, $mail); $cc array, string
$mail AssertableMessage, Email
$this->assertMailBcc($cc, $mail); $bcc array, string
$mail AssertableMessage, Email
$this->assertMailNotBcc($cc, $mail); $bcc array, string
$mail AssertableMessage, Email
$this->assertMailSender($sender, $mail); $sender array, string
$mail AssertableMessage, Email
$this->assertMailNotSender($sender, $mail); $sender array, string
$mail AssertableMessage, Email
$this->assertMailReturnPath($returnPath, $mail); $returnPath string
$mail AssertableMessage, Email
$this->assertMailNotReturnPath($returnPath, $mail); $returnPath string
$mail AssertableMessage, Email
Content Type Assertions Parameters
$this->assertMailIsPlain($mail); $mail AssertableMessage, Email
$this->assertMailIsNotPlain($mail); $mail AssertableMessage, Email
$this->assertMailHasPlainContent($mail); $mail AssertableMessage, Email
$this->assertMailDoesNotHavePlainContent($mail); $mail AssertableMessage, Email
$this->assertMailIsHtml($mail); $mail AssertableMessage, Email
$this->assertMailIsNotHtml($mail); $mail AssertableMessage, Email
$this->assertMailHasHtmlContent($mail); $mail AssertableMessage, Email
$this->assertMailDoesNotHaveHtmlContent($mail); $mail AssertableMessage, Email
$this->assertMailIsAlternative($mail); $mail AssertableMessage, Email
$this->assertMailIsNotAlternative($mail); $mail AssertableMessage, Email
$this->assertMailIsMixed($mail); $mail AssertableMessage, Email
$this->assertMailIsNotMixed($mail); $mail AssertableMessage, Email
Header Assertions Parameters
$this->assertMailHasHeader($header, $mail); $header string
$mail AssertableMessage, Email
$this->assertMailMissingHeader($header, $mail); $header string
$mail AssertableMessage, Email
$this->assertMailHeaderIs($header, $value, $mail); $header string
$value string
$mail AssertableMessage, Email
$this->assertMailHeaderIsNot($header, $value, $mail); $header string
$value string
$mail AssertableMessage, Email
Priority Assertions Parameters
$this->assertMailPriority($priority, $mail); $priority int
$mail AssertableMessage, Email
$this->assertMailNotPriority($priority, $mail); $priority int
$mail AssertableMessage, Email
$this->assertMailPriorityIsHighest($mail); $mail AssertableMessage, Email
$this->assertMailPriorityNotHighest($mail); $mail AssertableMessage, Email
$this->assertMailPriorityIsHigh($mail); $mail AssertableMessage, Email
$this->assertMailPriorityNotHigh($mail); $mail AssertableMessage, Email
$this->assertMailPriorityIsNormal($mail); $mail AssertableMessage, Email
$this->assertMailPriorityNotNormal($mail); $mail AssertableMessage, Email
$this->assertMailPriorityIsLow($mail); $mail AssertableMessage, Email
$this->assertMailPriorityNotLow($mail); $mail AssertableMessage, Email
$this->assertMailPriorityIsLowest($mail); $mail AssertableMessage, Email
$this->assertMailPriorityIsLowest($mail); $mail AssertableMessage, Email
Attachment Assertions Parameters
this->assertMailHasAttachment($filename); $filename string
$mail AssertableMessage, Email
this->assertMailHasAttachments(); $mail AssertableMessage, Email
this->assertMailMissingAttachment($filename); $filename string
$mail AssertableMessage, Email
this->assertMailMissingAttachments(); $mail AssertableMessage, Email
this->assertMailHasEmbeddedImage($filename); $filename string
$mail AssertableMessage, Email
this->assertMailHasEmbeddedImages(); $mail AssertableMessage, Email
this->assertMailMissingEmbeddedImage($filename); $filename string
$mail AssertableMessage, Email
this->assertMailMissingEmbeddedImages(); $mail AssertableMessage, Email

You should use each item of the interceptedMail() collection as the mail object for all assertions.

If you are injecting your own headers or need access to other headers in the email, use this assertion to verify they exist and are set properly. These assertions require the header name and the compiled email.

Other assertions

Since $this->interceptedMail() returns a collection of AssertableMessage objects. You are free to dissect and look into those objects using any methods available to Symfony's Email API. Head over to the Symfony Email Docs for more detailed info.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email brandon@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.

Credits

Sponsorship

Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more about us or join us!

License

The MIT License (MIT). Please see License File for more information.

kirschbaum-development/mail-intercept 适用场景与选型建议

kirschbaum-development/mail-intercept 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 442.23k 次下载、GitHub Stars 达 112, 最近一次更新时间为 2019 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「email」 「test」 「laravel」 「symfony mailer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 kirschbaum-development/mail-intercept 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 442.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 112
  • 点击次数: 33
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 112
  • Watchers: 13
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-12