Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Assert how many times a mail was sent or a job was pushed to the queue #20485

Merged
merged 4 commits into from
Aug 9, 2017
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
20 changes: 20 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,32 @@ class MailFake implements Mailer
*/
public function assertSent($mailable, $callback = null)
{
if(is_array($mailable)) {
return $this->assertSentTimes($mailable[0], $mailable[1], $callback);
}

PHPUnit::assertTrue(
$this->sent($mailable, $callback)->count() > 0,
"The expected [{$mailable}] mailable was not sent."
);
}

/**
* Assert if a mailable was sent a number of times based on a truth-test callback.
*
* @param string $mailable
* @param int $times
* @param callable|null $callback
* @return void
*/
public function assertSentTimes($mailable, $times = 1, $callback = null)
{
PHPUnit::assertTrue(
($count = $this->sent($mailable, $callback)->count()) === $times,
"The expected [{$mailable}] mailable was sent {$count} times instead of {$times} times."
);
}

/**
* Determine if a mailable was not sent based on a truth-test callback.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,32 @@ class QueueFake extends QueueManager implements Queue
*/
public function assertPushed($job, $callback = null)
{
if(is_array($job)) {
return $this->assertPushedTimes($mailable[0], $mailable[1], $callback);
}

PHPUnit::assertTrue(
$this->pushed($job, $callback)->count() > 0,
"The expected [{$job}] job was not pushed."
);
}

/**
* Assert if a job was pushed a number of times based on a truth-test callback.
*
* @param string $job
* @param int $times
* @param callable|null $callback
* @return void
*/
public function assertPushedTimes($job, $times, $callback = null)
{
PHPUnit::assertTrue(
($count = $this->pushed($job, $callback)->count()) === $times,
"The expected [{$job}] job was pushed {$count} times instead of {$times} times."
);
}

/**
* Assert if a job was pushed based on a truth-test callback.
*
Expand Down