Skip to content

Commit e790031

Browse files
committed
Added MailManager::forgetMailer()
* added test
1 parent a201572 commit e790031

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Illuminate/Mail/MailManager.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public function mailer($name = null)
7272
return $this->mailers[$name] = $this->get($name);
7373
}
7474

75+
/**
76+
* @param string $name
77+
* @return void
78+
*/
79+
public function forgetMailer($name)
80+
{
81+
if(isset($this->mailers[$name])){
82+
unset($this->mailers[$name]);
83+
}
84+
}
85+
7586
/**
7687
* Get a mailer driver instance.
7788
*

tests/Mail/MailManagerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Mail;
44

5+
use Illuminate\Mail\MailManager;
56
use Orchestra\Testbench\TestCase;
67

78
class MailManagerTest extends TestCase
@@ -32,4 +33,30 @@ public function emptyTransportConfigDataProvider()
3233
[null], [''], [' '],
3334
];
3435
}
36+
37+
public function testForgetMailer()
38+
{
39+
$this->app['config']->set('mail.mailers.custom_smtp', [
40+
'transport' => "smtp",
41+
'host' => "example.com",
42+
'port' => "25",
43+
'encryption' => "tls",
44+
'username' => "username",
45+
'password' => "password",
46+
'timeout' => 10,
47+
]);
48+
49+
/** @var MailManager $mailManager */
50+
$mailManager = $this->app['mail.manager'];
51+
$mailManager->mailer("custom_smtp");
52+
53+
$mailersProperty = new \ReflectionProperty($mailManager, 'mailers');
54+
$mailersProperty->setAccessible(true);
55+
56+
$this->assertArrayHasKey("custom_smtp", $mailersProperty->getValue($mailManager), "Mailer must exist in the \$mailers-property");
57+
58+
$mailManager->forgetMailer("custom_smtp");
59+
60+
$this->assertArrayNotHasKey("custom_smtp", $mailersProperty->getValue($mailManager), "Mailer must not exist in the \$mailers-property as it must have been removed with MailManager::forgetMailer()");
61+
}
3562
}

0 commit comments

Comments
 (0)