Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #91 from MarkVaughn/mark/mailable
Browse files Browse the repository at this point in the history
Allow mailer to intercept Mailable objects
  • Loading branch information
mattstauffer committed Feb 10, 2018
2 parents ae3a5bd + 69a321a commit 20272f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/MailThief.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions tests/InteractsWithMailTest.php
Expand Up @@ -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');
}
}
9 changes: 9 additions & 0 deletions tests/MailThiefTest.php
Expand Up @@ -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'));
}
}
11 changes: 11 additions & 0 deletions tests/TestMailable.php
@@ -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.