getContents(); // Only the ones that take their sender from a mailbox. A mailable with // no mailbox From has nothing to mismatch. if (! str_contains($code, 'mailboxEnvelope(') && ! str_contains($code, 'mailboxAddresses(')) { continue; } preg_match('/mailbox(?:Envelope|Addresses)\(\s*MailPurpose::([A-Z_]+)/', $code, $from); preg_match("/->mailer\('cp_'\.MailPurpose::([A-Z_]+)\)/", $code, $mailer); $fromPurpose = $from[1] ?? null; $mailerPurpose = $mailer[1] ?? null; if ($fromPurpose !== null && $fromPurpose !== $mailerPurpose) { $offenders[] = $file->getFilename().': From '.$fromPurpose.', mailer '.($mailerPurpose ?? 'DEFAULT'); } } expect($offenders)->toBe([]); }); it('sends each purpose over its own mailer, not over whatever mail.default is', function () { // The purpose mailers exist so that each mailbox authenticates as itself. // A mailable naming no mailer silently uses mail.default, which on this // installation is the plain smtp mailer with ONE account behind it. foreach (App\Services\Mail\MailPurpose::ALL as $purpose) { expect(config('mail.mailers.cp_'.$purpose)) ->toBe(['transport' => 'mailbox', 'purpose' => $purpose]); } });