Skip to content

Commit

Permalink
[10.x] Add 'Roundrobin' Symfony mailer transport driver (#49435)
Browse files Browse the repository at this point in the history
* add roundrobin symfony mailer transport driver

* add test for roundrobin transport driver

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
me-shaon and crynobone committed Dec 23, 2023
1 parent a77d6b6 commit 8e6e056
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions src/Illuminate/Mail/MailManager.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/Mail/MailRoundRobinTransportTest.php
@@ -0,0 +1,27 @@
<?php

namespace Illuminate\Tests\Integration\Mail;

use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Mailer\Transport\RoundRobinTransport;

class MailRoundRobinTransportTest extends TestCase
{
#[WithConfig('mail.default', 'roundrobin')]
#[WithConfig('mail.mailers.roundrobin', ['transport' => '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);
}
}

0 comments on commit 8e6e056

Please sign in to comment.