From f7d55a54a2c016a718ea03f10a3f2c239e7fdd31 Mon Sep 17 00:00:00 2001 From: Ahmed shamim Date: Tue, 19 Dec 2023 22:38:31 +0600 Subject: [PATCH 1/4] add roundrobin symfony mailer transport driver --- src/Illuminate/Mail/MailManager.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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. * From f662dfa978719e9d391c07ec05fc8d66614ae8e7 Mon Sep 17 00:00:00 2001 From: Ahmed shamim Date: Tue, 19 Dec 2023 22:38:49 +0600 Subject: [PATCH 2/4] add test for roundrobin transport driver --- tests/Mail/MailRoundRobinTransportTest.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/Mail/MailRoundRobinTransportTest.php diff --git a/tests/Mail/MailRoundRobinTransportTest.php b/tests/Mail/MailRoundRobinTransportTest.php new file mode 100644 index 000000000000..5b45f720faf0 --- /dev/null +++ b/tests/Mail/MailRoundRobinTransportTest.php @@ -0,0 +1,51 @@ +app['config']->set('mail.default', 'roundrobin'); + + $this->app['config']->set('mail.mailers', [ + 'roundrobin' => [ + 'transport' => 'roundrobin', + 'mailers' => [ + 'sendmail', + 'array', + ], + ], + + 'sendmail' => [ + 'transport' => 'sendmail', + 'path' => '/usr/sbin/sendmail -bs', + ], + + 'array' => [ + 'transport' => 'array', + ], + ]); + + $transport = app('mailer')->getSymfonyTransport(); + $this->assertInstanceOf(RoundRobinTransport::class, $transport); + } + + public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration() + { + $this->app['config']->set('mail.driver', 'roundrobin'); + + $this->app['config']->set('mail.mailers', [ + 'sendmail', + 'array', + ]); + + $this->app['config']->set('mail.sendmail', '/usr/sbin/sendmail -bs'); + + $transport = app('mailer')->getSymfonyTransport(); + $this->assertInstanceOf(RoundRobinTransport::class, $transport); + } +} From f3df790d2898516b74db35d6604bda70014590d0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Dec 2023 09:22:40 +0800 Subject: [PATCH 3/4] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- .../Mail/MailRoundRobinTransportTest.php | 28 ++++++++++ tests/Mail/MailRoundRobinTransportTest.php | 51 ------------------- 3 files changed, 29 insertions(+), 52 deletions(-) create mode 100644 tests/Integration/Mail/MailRoundRobinTransportTest.php delete mode 100644 tests/Mail/MailRoundRobinTransportTest.php diff --git a/composer.json b/composer.json index 9e7705b73db9..e65cd915b1f4 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/tests/Integration/Mail/MailRoundRobinTransportTest.php b/tests/Integration/Mail/MailRoundRobinTransportTest.php new file mode 100644 index 000000000000..ba0c154ccc89 --- /dev/null +++ b/tests/Integration/Mail/MailRoundRobinTransportTest.php @@ -0,0 +1,28 @@ + '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); + } +} diff --git a/tests/Mail/MailRoundRobinTransportTest.php b/tests/Mail/MailRoundRobinTransportTest.php deleted file mode 100644 index 5b45f720faf0..000000000000 --- a/tests/Mail/MailRoundRobinTransportTest.php +++ /dev/null @@ -1,51 +0,0 @@ -app['config']->set('mail.default', 'roundrobin'); - - $this->app['config']->set('mail.mailers', [ - 'roundrobin' => [ - 'transport' => 'roundrobin', - 'mailers' => [ - 'sendmail', - 'array', - ], - ], - - 'sendmail' => [ - 'transport' => 'sendmail', - 'path' => '/usr/sbin/sendmail -bs', - ], - - 'array' => [ - 'transport' => 'array', - ], - ]); - - $transport = app('mailer')->getSymfonyTransport(); - $this->assertInstanceOf(RoundRobinTransport::class, $transport); - } - - public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration() - { - $this->app['config']->set('mail.driver', 'roundrobin'); - - $this->app['config']->set('mail.mailers', [ - 'sendmail', - 'array', - ]); - - $this->app['config']->set('mail.sendmail', '/usr/sbin/sendmail -bs'); - - $transport = app('mailer')->getSymfonyTransport(); - $this->assertInstanceOf(RoundRobinTransport::class, $transport); - } -} From 865700953ada2b5e6dfea75972e873b1062570e8 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Dec 2023 09:31:51 +0800 Subject: [PATCH 4/4] wip Signed-off-by: Mior Muhammad Zaki --- tests/Integration/Mail/MailRoundRobinTransportTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Mail/MailRoundRobinTransportTest.php b/tests/Integration/Mail/MailRoundRobinTransportTest.php index ba0c154ccc89..cb1bd3c05222 100644 --- a/tests/Integration/Mail/MailRoundRobinTransportTest.php +++ b/tests/Integration/Mail/MailRoundRobinTransportTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Mail; -use Illuminate\Contracts\Config\Repository; use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; use Symfony\Component\Mailer\Transport\RoundRobinTransport;