- What is tightenco/mailthief and how does it work?
- MailThief is a fake mailer for Laravel that rebinds the mailer in the container to an in-memory store, so anything sent through the Mail facade is captured instead of delivered. It registers fluent assertion macros on your test case so you can inspect recipients, subject lines, and rendered bodies. It is strictly a test-time service double and never runs in production.
- How do I install MailThief in a Laravel project?
- Install it as a dev dependency with composer require --dev tightenco/mailthief, pinned to the exact 0.3.14 release since the package is a dead 0.x line. Laravel auto-discovers the service provider; Lumen needs manual registration plus a MailThief alias in bootstrap/app.php. Then call MailThief::hijack() in your base TestCase setUp() before any mail is sent.
- Which Laravel versions does MailThief support?
- It targets Laravel 5.1 through 5.4 and Lumen applications that send mail through the Mail facade or the MailThief alias. On Laravel 5.5 and newer you should use the framework's built-in Mail::fake() instead, which covers recipients, subjects, bodies, attachments, and queued mail. Anything outside the legacy range is unsupported.
- Does MailThief capture queued mail?
- No. Mailables implementing ShouldQueue that are dispatched through database or redis queue drivers never reach the in-memory store, so those assertions silently pass while checking nothing. Audit every existing mail assertion to confirm a message was actually captured. This is the package's highest-risk blind spot and the first thing to verify.
- How do I assert on mail sent in a Laravel test with MailThief?
- After MailThief::hijack() in setUp(), send mail normally and then chain assertions such as assertSent and assertSentTo, or inspect the last captured message for subject and body. Fluent helpers cover to, cc, and bcc recipients plus subject and rendered content. Prefer anchoring assertions to recipient, subject, view name, or mailable class, because raw body assertions break easily.
- Does MailThief work with Lumen?
- Yes, with manual setup. Register the MailThief service provider in bootstrap/app.php and add a MailThief alias, since Lumen does not use Laravel's package auto-discovery. After that, hijack the mailer in your test bootstrap exactly as you would in Laravel.
- Is MailThief still maintained?
- No. The last release was 0.3.14 on 2018-02-10, the line is pre-1.0, and there is no upstream maintainer to escalate to. Pin the exact version, because minor bumps on a 0.x line may include breaking changes and no patch releases will follow. Open a removal ticket tied to your next framework or PHP upgrade so the debt has a name and a date.
- Should I use MailThief or Laravel's Mail::fake()?
- For Laravel 5.5 and newer, always use the framework's Mail::fake(), which is actively maintained and covers recipients, subjects, bodies, attachments, and queued mail. MailThief only makes sense for legacy 5.1 to 5.4 or Lumen codebases that predate that API. Do not run both at once, since both replace the mailer binding and the last writer wins, producing confusing no-message-found failures.
- Does MailThief work with PHP 8 and PHPUnit 8 or later?
- Not without changes. It predates typed setUp(): void signatures, so PHPUnit 8 and above throw signature-mismatch fatals. In practice you either pin a legacy PHPUnit and PHP toolchain matching Laravel 5.1 to 5.4, or migrate to Mail::fake() and drop the package.
- Can I inspect the rendered HTML and plain-text body of captured mail?
- Yes. Each captured message exposes the rendered HTML and the plain-text view, so you can assert on body content when the case genuinely requires it. Keep those assertions narrow, since they break on cosmetic template changes and on to-array internals rather than on real product regressions.