Skip to content

Commit 8e6e056

Browse files
me-shaoncrynobone
andauthored
[10.x] Add 'Roundrobin' Symfony mailer transport driver (#49435)
* add roundrobin symfony mailer transport driver * add test for roundrobin transport driver * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Mior Muhammad Zaki <[email protected]>
1 parent a77d6b6 commit 8e6e056

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"league/flysystem-sftp-v3": "^3.0",
106106
"mockery/mockery": "^1.5.1",
107107
"nyholm/psr7": "^1.2",
108-
"orchestra/testbench-core": "^8.15.1",
108+
"orchestra/testbench-core": "^8.18",
109109
"pda/pheanstalk": "^4.0",
110110
"phpstan/phpstan": "^1.4.7",
111111
"phpunit/phpunit": "^10.0.7",

src/Illuminate/Mail/MailManager.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
2222
use Symfony\Component\Mailer\Transport\Dsn;
2323
use Symfony\Component\Mailer\Transport\FailoverTransport;
24+
use Symfony\Component\Mailer\Transport\RoundRobinTransport;
2425
use Symfony\Component\Mailer\Transport\SendmailTransport;
2526
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
2627
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
@@ -375,6 +376,34 @@ protected function createFailoverTransport(array $config)
375376
return new FailoverTransport($transports);
376377
}
377378

379+
/**
380+
* Create an instance of the Symfony Roundrobin Transport driver.
381+
*
382+
* @param array $config
383+
* @return \Symfony\Component\Mailer\Transport\RoundRobinTransport
384+
*/
385+
protected function createRoundrobinTransport(array $config)
386+
{
387+
$transports = [];
388+
389+
foreach ($config['mailers'] as $name) {
390+
$config = $this->getConfig($name);
391+
392+
if (is_null($config)) {
393+
throw new InvalidArgumentException("Mailer [{$name}] is not defined.");
394+
}
395+
396+
// Now, we will check if the "driver" key exists and if it does we will set
397+
// the transport configuration parameter in order to offer compatibility
398+
// with any Laravel <= 6.x application style mail configuration files.
399+
$transports[] = $this->app['config']['mail.driver']
400+
? $this->createSymfonyTransport(array_merge($config, ['transport' => $name]))
401+
: $this->createSymfonyTransport($config);
402+
}
403+
404+
return new RoundRobinTransport($transports);
405+
}
406+
378407
/**
379408
* Create an instance of the Log Transport driver.
380409
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Mail;
4+
5+
use Orchestra\Testbench\Attributes\WithConfig;
6+
use Orchestra\Testbench\TestCase;
7+
use Symfony\Component\Mailer\Transport\RoundRobinTransport;
8+
9+
class MailRoundRobinTransportTest extends TestCase
10+
{
11+
#[WithConfig('mail.default', 'roundrobin')]
12+
#[WithConfig('mail.mailers.roundrobin', ['transport' => 'roundrobin', 'mailers' => ['sendmail', 'array']])]
13+
public function testGetRoundRobinTransportWithConfiguredTransports()
14+
{
15+
$transport = app('mailer')->getSymfonyTransport();
16+
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
17+
}
18+
19+
#[WithConfig('mail.driver', 'roundrobin')]
20+
#[WithConfig('mail.mailers', ['sendmail', 'array'])]
21+
#[WithConfig('mail.sendmail', '/usr/sbin/sendmail -bs')]
22+
public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration()
23+
{
24+
$transport = app('mailer')->getSymfonyTransport();
25+
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
26+
}
27+
}

0 commit comments

Comments
 (0)