Skip to content

Commit d9d99e1

Browse files
adamwathantaylorotwell
authored andcommitted
Make Mailer macroable (#18763)
1 parent 0c30a6a commit d9d99e1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Illuminate/Mail/Mailer.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Arr;
77
use InvalidArgumentException;
88
use Illuminate\Contracts\View\Factory;
9+
use Illuminate\Support\Traits\Macroable;
910
use Illuminate\Contracts\Support\Htmlable;
1011
use Illuminate\Contracts\Events\Dispatcher;
1112
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -16,6 +17,8 @@
1617

1718
class Mailer implements MailerContract, MailQueueContract
1819
{
20+
use Macroable;
21+
1922
/**
2023
* The view factory instance.
2124
*

tests/Mail/MailMailerTest.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Tests\Mail;
44

55
use Mockery as m;
6+
use Illuminate\Mail\Mailer;
67
use PHPUnit\Framework\TestCase;
78
use Illuminate\Support\HtmlString;
89

@@ -148,9 +149,22 @@ public function testEventsAreDispatched()
148149
});
149150
}
150151

152+
public function testMacroable()
153+
{
154+
Mailer::macro('foo', function () {
155+
return 'bar';
156+
});
157+
158+
$mailer = $this->getMailer();
159+
160+
$this->assertEquals(
161+
'bar', $mailer->foo()
162+
);
163+
}
164+
151165
protected function getMailer($events = null)
152166
{
153-
return new \Illuminate\Mail\Mailer(m::mock('Illuminate\Contracts\View\Factory'), m::mock('Swift_Mailer'), $events);
167+
return new Mailer(m::mock('Illuminate\Contracts\View\Factory'), m::mock('Swift_Mailer'), $events);
154168
}
155169

156170
public function setSwiftMailer($mailer)

0 commit comments

Comments
 (0)