Permalink
Browse files

Merge pull request #91 from MarkVaughn/mark/mailable

Allow mailer to intercept Mailable objects
  • Loading branch information...
mattstauffer committed Feb 10, 2018
2 parents ae3a5bd + 69a321a commit 20272f0721d2f07c13a399e9a7fa7b2a03a692ff
Showing with 44 additions and 3 deletions.
  1. +8 −3 src/MailThief.php
  2. +16 −0 tests/InteractsWithMailTest.php
  3. +9 −0 tests/MailThiefTest.php
  4. +11 −0 tests/TestMailable.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;
@@ -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');
}
}
@@ -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'));
}
}
@@ -0,0 +1,11 @@
<?php
use Illuminate\Mail\Mailable;
class TestMailable extends Mailable
{
public function build()
{
return $this->view('example-view');
}
}

0 comments on commit 20272f0

Please sign in to comment.