Skip to content

Commit

Permalink
test a mailable that implements ShouldQueue is queued and not sent
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjatenee committed Aug 12, 2017
1 parent 1052925 commit 3d9e734
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Support/SupportTestingMailFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Testing\Fakes\MailFake;
use PHPUnit\Framework\ExpectationFailedException;
use Illuminate\Contracts\Queue\ShouldQueue;

class MailFakeTest extends TestCase
{
Expand Down Expand Up @@ -88,6 +89,20 @@ public function testAssertQueuedTimes()
$this->fake->assertQueued(MailableStub::class, 2);
}

public function testSendQueuesAMailable()
{
$this->fake->to('[email protected]')->send(new QueueableMailableStub);

try {
$this->fake->assertSent(QueueableMailableStub::class);
} catch (ExpectationFailedException $exception) {
$this->assertEquals('The expected [Illuminate\Tests\Support\QueueableMailableStub] mailable was not sent.
Failed asserting that false is true.', $exception->getMessage());
}

$this->fake->assertQueued(QueueableMailableStub::class);
}

public function testAssertNothingSent()
{
$this->fake->assertNothingSent();
Expand Down Expand Up @@ -120,3 +135,21 @@ public function build()
->withLastName('Otwell');
}
}

class QueueableMailableStub extends Mailable implements ShouldQueue
{
public $framework = 'Laravel';

protected $version = '5.5';

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->with('first_name', 'Taylor')
->withLastName('Otwell');
}
}

0 comments on commit 3d9e734

Please sign in to comment.