Skip to content

Commit e9f18fc

Browse files
[12.x] Allow configuration of retry period for RoundRobin and Failover mail transports (#55222)
* Replace RoundRobinTransport integration test with 'regular' test Consistent with FailoverTransport * Use single function for creating Failover and RoundRobin (mail) transports * Allow configuring of retry period on RoundRobin and Failover mail transports * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 136361c commit e9f18fc

File tree

4 files changed

+69
-46
lines changed

4 files changed

+69
-46
lines changed

config/mail.php

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
'smtp',
8686
'log',
8787
],
88+
'retry_after' => 60,
8889
],
8990

9091
'roundrobin' => [
@@ -93,6 +94,7 @@
9394
'ses',
9495
'postmark',
9596
],
97+
'retry_after' => 60,
9698
],
9799

98100
],

src/Illuminate/Mail/MailManager.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -385,24 +385,7 @@ protected function createPostmarkTransport(array $config)
385385
*/
386386
protected function createFailoverTransport(array $config)
387387
{
388-
$transports = [];
389-
390-
foreach ($config['mailers'] as $name) {
391-
$config = $this->getConfig($name);
392-
393-
if (is_null($config)) {
394-
throw new InvalidArgumentException("Mailer [{$name}] is not defined.");
395-
}
396-
397-
// Now, we will check if the "driver" key exists and if it does we will set
398-
// the transport configuration parameter in order to offer compatibility
399-
// with any Laravel <= 6.x application style mail configuration files.
400-
$transports[] = $this->app['config']['mail.driver']
401-
? $this->createSymfonyTransport(array_merge($config, ['transport' => $name]))
402-
: $this->createSymfonyTransport($config);
403-
}
404-
405-
return new FailoverTransport($transports);
388+
return $this->createRoundrobinTransportOfClass($config, FailoverTransport::class);
406389
}
407390

408391
/**
@@ -412,6 +395,20 @@ protected function createFailoverTransport(array $config)
412395
* @return \Symfony\Component\Mailer\Transport\RoundRobinTransport
413396
*/
414397
protected function createRoundrobinTransport(array $config)
398+
{
399+
return $this->createRoundrobinTransportOfClass($config, RoundRobinTransport::class);
400+
}
401+
402+
/**
403+
* Create an instance of supplied class extending the Symfony Roundrobin Transport driver.
404+
*
405+
* @template TClass of \Symfony\Component\Mailer\Transport\RoundRobinTransport
406+
*
407+
* @param array $config
408+
* @param class-string<TClass> $class
409+
* @return TClass
410+
*/
411+
protected function createRoundrobinTransportOfClass(array $config, string $class)
415412
{
416413
$transports = [];
417414

@@ -430,7 +427,7 @@ protected function createRoundrobinTransport(array $config)
430427
: $this->createSymfonyTransport($config);
431428
}
432429

433-
return new RoundRobinTransport($transports);
430+
return new $class($transports, $config['retry_after'] ?? 60);
434431
}
435432

436433
/**

tests/Integration/Mail/MailRoundRobinTransportTest.php

-27
This file was deleted.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Mail;
4+
5+
use Orchestra\Testbench\TestCase;
6+
use Symfony\Component\Mailer\Transport\RoundRobinTransport;
7+
8+
class MailRoundRobinTransportTest extends TestCase
9+
{
10+
public function testGetRoundRobinTransportWithConfiguredTransports()
11+
{
12+
$this->app['config']->set('mail.default', 'roundrobin');
13+
14+
$this->app['config']->set('mail.mailers', [
15+
'roundrobin' => [
16+
'transport' => 'roundrobin',
17+
'mailers' => [
18+
'sendmail',
19+
'array',
20+
],
21+
],
22+
23+
'sendmail' => [
24+
'transport' => 'sendmail',
25+
'path' => '/usr/sbin/sendmail -bs',
26+
],
27+
28+
'array' => [
29+
'transport' => 'array',
30+
],
31+
]);
32+
33+
$transport = app('mailer')->getSymfonyTransport();
34+
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
35+
}
36+
37+
public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration()
38+
{
39+
$this->app['config']->set('mail.driver', 'roundrobin');
40+
41+
$this->app['config']->set('mail.mailers', [
42+
'sendmail',
43+
'array',
44+
]);
45+
46+
$this->app['config']->set('mail.sendmail', '/usr/sbin/sendmail -bs');
47+
48+
$transport = app('mailer')->getSymfonyTransport();
49+
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
50+
}
51+
}

0 commit comments

Comments
 (0)