diff --git a/composer.json b/composer.json index 5af97271ad45..dac49e5946c7 100644 --- a/composer.json +++ b/composer.json @@ -105,7 +105,7 @@ "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.5.1", "nyholm/psr7": "^1.2", - "orchestra/testbench-core": "^8.15.1", + "orchestra/testbench-core": "^8.18", "pda/pheanstalk": "^4.0", "phpstan/phpstan": "^1.4.7", "phpunit/phpunit": "^10.0.7", diff --git a/src/Illuminate/Mail/MailManager.php b/src/Illuminate/Mail/MailManager.php index ecf094af2c15..f821aa933e40 100644 --- a/src/Illuminate/Mail/MailManager.php +++ b/src/Illuminate/Mail/MailManager.php @@ -21,6 +21,7 @@ use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory; use Symfony\Component\Mailer\Transport\Dsn; use Symfony\Component\Mailer\Transport\FailoverTransport; +use Symfony\Component\Mailer\Transport\RoundRobinTransport; use Symfony\Component\Mailer\Transport\SendmailTransport; use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory; @@ -375,6 +376,34 @@ protected function createFailoverTransport(array $config) return new FailoverTransport($transports); } + /** + * Create an instance of the Symfony Roundrobin Transport driver. + * + * @param array $config + * @return \Symfony\Component\Mailer\Transport\RoundRobinTransport + */ + protected function createRoundrobinTransport(array $config) + { + $transports = []; + + foreach ($config['mailers'] as $name) { + $config = $this->getConfig($name); + + if (is_null($config)) { + throw new InvalidArgumentException("Mailer [{$name}] is not defined."); + } + + // Now, we will check if the "driver" key exists and if it does we will set + // the transport configuration parameter in order to offer compatibility + // with any Laravel <= 6.x application style mail configuration files. + $transports[] = $this->app['config']['mail.driver'] + ? $this->createSymfonyTransport(array_merge($config, ['transport' => $name])) + : $this->createSymfonyTransport($config); + } + + return new RoundRobinTransport($transports); + } + /** * Create an instance of the Log Transport driver. * diff --git a/tests/Integration/Mail/MailRoundRobinTransportTest.php b/tests/Integration/Mail/MailRoundRobinTransportTest.php new file mode 100644 index 000000000000..cb1bd3c05222 --- /dev/null +++ b/tests/Integration/Mail/MailRoundRobinTransportTest.php @@ -0,0 +1,27 @@ + 'roundrobin', 'mailers' => ['sendmail', 'array']])] + public function testGetRoundRobinTransportWithConfiguredTransports() + { + $transport = app('mailer')->getSymfonyTransport(); + $this->assertInstanceOf(RoundRobinTransport::class, $transport); + } + + #[WithConfig('mail.driver', 'roundrobin')] + #[WithConfig('mail.mailers', ['sendmail', 'array'])] + #[WithConfig('mail.sendmail', '/usr/sbin/sendmail -bs')] + public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration() + { + $transport = app('mailer')->getSymfonyTransport(); + $this->assertInstanceOf(RoundRobinTransport::class, $transport); + } +}