Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,17 @@ private function ensureAttachmentsAreHydrated()
});
}

/**
* Determine if the mailable will be sent by the given mailer.
*
* @param string $mailer
* @return bool
*/
public function usesMailer($mailer)
{
return $this->mailer === $mailer;
}

/**
* Set the name of the mailer that should send the message.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MailFake implements Factory, Fake, Mailer, MailQueue
public function __construct(MailManager $manager)
{
$this->manager = $manager;
$this->currentMailer = $manager->getDefaultDriver();
}

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@ public function testMailerMayBeSet()
$mailable = new WelcomeMailableStub;

$mailable->mailer('array');
$this->assertTrue($mailable->usesMailer('array'));

$mailable = unserialize(serialize($mailable));

$this->assertSame('array', $mailable->mailer);
$mailable->mailer('smtp');
$this->assertTrue($mailable->usesMailer('smtp'));
$this->assertFalse($mailable->usesMailer('ses'));
}

public function testMailablePriorityGetsSent()
Expand Down
32 changes: 31 additions & 1 deletion tests/Support/SupportTestingMailFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class SupportTestingMailFakeTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->mailManager = m::mock(MailManager::class);
$this->mailManager = m::mock(MailManager::class, function ($mock) {
$mock->shouldReceive('getDefaultDriver')
->andReturn('smtp');
});
$this->fake = new MailFake($this->mailManager);
$this->mailable = new MailableStub;
}
Expand Down Expand Up @@ -380,6 +383,33 @@ public function testMissingMethodsAreForwarded()

$this->assertEquals('bar', $this->fake->foo());
}

public function testAssertMailer()
{
$this->fake->to('taylor@laravel.com')->send($this->mailable);

$this->fake->assertSent(MailableStub::class, function ($mail) {
return $mail->usesMailer('smtp');
});

$this->fake->mailer('ses')->to('taylor@laravel.com')->send($this->mailable);

$this->fake->assertSent(MailableStub::class, function ($mail) {
return $mail->usesMailer('ses');
});

$this->fake->mailer('sendgrid')->to('taylor@laravel.com')->queue($this->mailable);

$this->fake->assertQueued(MailableStub::class, function ($mail) {
return $mail->usesMailer('sendgrid');
});

$this->fake->mailer('mailjet')->to('taylor@laravel.com')->queue($this->mailable);

$this->fake->assertQueued(MailableStub::class, function ($mail) {
return $mail->usesMailer('mailjet');
});
}
}

class MailableStub extends Mailable
Expand Down