'setting'], ['value' => json_encode(['company' => 'Thế Giới Số'])]); Setting::updateOrCreate(['key' => 'smtp'], ['value' => json_encode([ 'host' => $host, 'port' => 465, 'user' => 'noreply@tgs.com.vn', 'password' => SignRSA::EncryptFunc('secret'), 'encryption' => 'ssl', 'from_address' => 'noreply@tgs.com.vn', 'from_name' => 'TGS', ])]); Cache::forget(MailSettings::cacheKey()); } private function hostSeenByQueuedJob(): ?string { dispatch(fn () => Cache::put('test:queued-mail-host', config('mail.mailers.smtp.host'))); return Cache::pull('test:queued-mail-host'); } public function test_queued_jobs_use_smtp_from_settings_and_pick_up_changes(): void { config(['queue.default' => 'sync']); $this->saveSmtp('smtp.settings-one.test'); $this->assertSame('smtp.settings-one.test', $this->hostSeenByQueuedJob()); $this->assertSame('noreply@tgs.com.vn', config('mail.from.address')); $this->assertSame('secret', config('mail.mailers.smtp.password')); $this->saveSmtp('smtp.settings-two.test'); $this->assertSame('smtp.settings-two.test', $this->hostSeenByQueuedJob()); } public function test_system_cc_and_bcc_are_applied_without_duplicate_recipients(): void { $this->saveSmtp('smtp.settings.test'); $smtp = Setting::where('key', 'smtp')->firstOrFail(); $values = json_decode((string) $smtp->value, true); $values['cc'] = ['audit@example.com', 'customer@example.com']; $values['bcc'] = ['archive@example.com', 'audit@example.com']; $smtp->update(['value' => json_encode($values)]); Cache::forget(MailSettings::cacheKey()); $message = (new Email())->to('customer@example.com')->subject('Test'); app(ApplySystemRecipients::class)->handle(new MessageSending($message, [])); $this->assertSame(['audit@example.com'], array_map(fn ($address) => $address->getAddress(), $message->getCc())); $this->assertSame(['archive@example.com'], array_map(fn ($address) => $address->getAddress(), $message->getBcc())); } }