Skip to content

Commit

Permalink
clean up fakes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 9, 2017
1 parent 75e08f9 commit e657f6e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
21 changes: 20 additions & 1 deletion src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,36 @@ class BusFake implements Dispatcher
* Assert if a job was dispatched based on a truth-test callback.
*
* @param string $command
* @param callable|null $callback
* @param callable|int|null $callback
* @return void
*/
public function assertDispatched($command, $callback = null)
{
if (is_numeric($callback)) {
return $this->assertDispatchedTimes($command, $callback);
}

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

/**
* Assert if a job was pushed a number of times.
*
* @param string $command
* @param int $times
* @return void
*/
protected function assertDispatchedTimes($command, $times = 1)
{
PHPUnit::assertTrue(
($count = $this->dispatched($command)->count()) === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
);
}

/**
* Determine if a job was dispatched based on a truth-test callback.
*
Expand Down
15 changes: 7 additions & 8 deletions src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class MailFake implements Mailer
* Assert if a mailable was sent based on a truth-test callback.
*
* @param string $mailable
* @param callable|null $callback
* @param callable|int|null $callback
* @return void
*/
public function assertSent($mailable, $callback = null)
{
if(is_array($mailable)) {
return $this->assertSentTimes($mailable[0], $mailable[1], $callback);
if (is_numeric($callback)) {
return $this->assertSentTimes($mailable, $callback);
}

PHPUnit::assertTrue(
Expand All @@ -35,17 +35,16 @@ public function assertSent($mailable, $callback = null)
}

/**
* Assert if a mailable was sent a number of times based on a truth-test callback.
* Assert if a mailable was sent a number of times.
*
* @param string $mailable
* @param int $times
* @param callable|null $callback
* @param int $times
* @return void
*/
public function assertSentTimes($mailable, $times = 1, $callback = null)
protected function assertSentTimes($mailable, $times = 1)
{
PHPUnit::assertTrue(
($count = $this->sent($mailable, $callback)->count()) === $times,
($count = $this->sent($mailable)->count()) === $times,
"The expected [{$mailable}] mailable was sent {$count} times instead of {$times} times."
);
}
Expand Down
15 changes: 7 additions & 8 deletions src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class QueueFake extends QueueManager implements Queue
* Assert if a job was pushed based on a truth-test callback.
*
* @param string $job
* @param callable|null $callback
* @param callable|int|null $callback
* @return void
*/
public function assertPushed($job, $callback = null)
{
if(is_array($job)) {
return $this->assertPushedTimes($mailable[0], $mailable[1], $callback);
if (is_numeric($callback)) {
return $this->assertPushedTimes($job, $callback);
}

PHPUnit::assertTrue(
Expand All @@ -35,17 +35,16 @@ public function assertPushed($job, $callback = null)
}

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

0 comments on commit e657f6e

Please sign in to comment.