Skip to content

Commit

Permalink
Show the names of any Mailables which were queued unexpectedly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ohnotnow committed Jan 11, 2020
1 parent d86dbd2 commit 45ba8d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function assertNotSent($mailable, $callback = null)
*/
public function assertNothingSent()
{
$mailableNames = collect($this->mailables)->values()->map(function ($mailable) {
$mailableNames = collect($this->mailables)->map(function ($mailable) {
return get_class($mailable);
})->join(', ');
PHPUnit::assertEmpty($this->mailables, 'The following Mailables were sent unexpectedly: ' . $mailableNames);
Expand Down Expand Up @@ -148,7 +148,10 @@ public function assertNotQueued($mailable, $callback = null)
*/
public function assertNothingQueued()
{
PHPUnit::assertEmpty($this->queuedMailables, 'Mailables were queued unexpectedly.');
$mailableNames = collect($this->queuedMailables)->map(function ($mailable) {
return get_class($mailable);
})->join(', ');
PHPUnit::assertEmpty($this->queuedMailables, 'The following Mailables were queued unexpectedly: ' . $mailableNames);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/Support/SupportTestingMailFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ public function testAssertNothingSent()
$this->assertThat($e, new ExceptionMessage('The following Mailables were sent unexpectedly: Illuminate\Tests\Support\MailableStub'));
}
}

public function testAssertNothingQueued()
{
$this->fake->assertNothingQueued();

$this->fake->to('[email protected]')->queue($this->mailable);

try {
$this->fake->assertNothingQueued();
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertThat($e, new ExceptionMessage('The following Mailables were queued unexpectedly: Illuminate\Tests\Support\MailableStub'));
}
}
}

class MailableStub extends Mailable implements MailableContract
Expand Down

0 comments on commit 45ba8d8

Please sign in to comment.