sendCount++; $this->captured = $message; return [ 'deliveredTo' => 1, 'type' => $this->getType(), 'results' => [['recipient' => $message->getTo()[0]['email'] ?? '', 'status' => 'sent']], ]; } } class MailsTest extends TestCase { public function testLegacyMailPayloadIsSentByMailsWorker(): void { $adapter = new SpyMailAdapter(); $registry = new Registry(); $registry->set('smtp', static fn () => $adapter); $previousSmtpHost = \getenv('_APP_SMTP_HOST'); \putenv('_APP_SMTP_HOST=spy.smtp.test'); try { $worker = new Mails(); $worker->action( new Message([ 'pid' => 'pid', 'queue' => 'v1-mails', 'timestamp' => \time(), 'payload' => [ 'recipient' => 'legacy@example.test', 'name' => 'Legacy User', 'subject' => 'Hello {{name}}', 'body' => 'Body {{name}}', 'variables' => ['name' => 'Legacy'], 'customMailOptions' => [ 'senderEmail' => 'sender@example.test', 'senderName' => 'Custom Sender', 'replyToEmail' => 'reply@example.test', 'replyToName' => 'Custom Reply', ], ], ]), new Document(['$id' => 'project-x']), $registry, new Log(), ); } finally { \putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost); } $this->assertSame(1, $adapter->sendCount); $this->assertNotNull($adapter->captured); $message = $adapter->captured; $this->assertSame('legacy@example.test', $message->getTo()[0]['email'] ?? ''); $this->assertSame('Legacy User', $message->getTo()[0]['name'] ?? ''); $this->assertSame('Hello Legacy', $message->getSubject()); $this->assertSame('sender@example.test', $message->getFromEmail()); $this->assertSame('Custom Sender', $message->getFromName()); $this->assertSame('reply@example.test', $message->getReplyToEmail()); $this->assertSame('Custom Reply', $message->getReplyToName()); } }