diff --git a/src/MailThief.php b/src/MailThief.php index 01ab796..90c9d75 100644 --- a/src/MailThief.php +++ b/src/MailThief.php @@ -2,14 +2,13 @@ namespace MailThief; -use Illuminate\Contracts\Mail\MailQueue; +use Illuminate\Contracts\Config\Repository as ConfigRepository; +use Illuminate\Contracts\Mail\Mailable; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Mail; use Illuminate\Support\HtmlString; -use Illuminate\Contracts\Config\Repository as ConfigRepository; use InvalidArgumentException; use MailThief\Support\MailThiefCollection; @@ -60,6 +59,12 @@ public function raw($text, $callback) public function send($view, array $data = [], $callback = null) { + if ($view instanceof Mailable) { + $view->send($this); + + return; + } + $callback = $callback ?: null; $data['message'] = new NullMessageForView; diff --git a/tests/InteractsWithMailTest.php b/tests/InteractsWithMailTest.php index 5190795..0b5eb72 100644 --- a/tests/InteractsWithMailTest.php +++ b/tests/InteractsWithMailTest.php @@ -190,4 +190,20 @@ public function test_global_from() $this->seeMessageFrom('me@example.com'); $this->seeMessageFrom('me@example.com', 'Example Person'); } + + public function test_with_mailables() + { + $mailer = $this->mailer = $this->getMailThief(); + + $mailable = new TestMailable(); + $mailable->to('john@example.com') + ->from('me@example.com', 'Example Person') + ->subject('Message for you'); + + $mailer->send($mailable); + + $this->seeMessageFrom('me@example.com'); + $this->seeMessageFrom('me@example.com', 'Example Person'); + $this->seeInSubjects('Message for you'); + } } diff --git a/tests/MailThiefTest.php b/tests/MailThiefTest.php index edb7b75..a8fe26d 100644 --- a/tests/MailThiefTest.php +++ b/tests/MailThiefTest.php @@ -450,4 +450,13 @@ public function test_it_gets_subjects() $this->assertEquals($messages, $mailer->subjects()->all()); } + + public function test_it_sends_mailables() + { + $mailer = $this->getMailThief(); + $mailable = new TestMailable(); + $mailable->to('john@example.com'); + $mailer->send($mailable); + $this->assertTrue($mailer->hasMessageFor('john@example.com')); + } } diff --git a/tests/TestMailable.php b/tests/TestMailable.php new file mode 100644 index 0000000..24102a8 --- /dev/null +++ b/tests/TestMailable.php @@ -0,0 +1,11 @@ +view('example-view'); + } +}