Skip to content

Commit

Permalink
adjust assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 10, 2020
1 parent 54ef968 commit e59597f
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function assertDispatched($command, $callback = null)
}

PHPUnit::assertTrue(
$this->dispatched($command, $callback)->count() > 0,
$this->dispatched($command, $callback)->count() > 0 ||
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
"The expected [{$command}] job was not dispatched."
);
}
Expand All @@ -79,73 +80,77 @@ public function assertDispatched($command, $callback = null)
*/
public function assertDispatchedTimes($command, $times = 1)
{
$count = $this->dispatched($command)->count() +
$this->dispatchedAfterResponse($command)->count();

PHPUnit::assertTrue(
($count = $this->dispatched($command)->count()) === $times,
$count === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
);
}

/**
* Assert if a job was pushed after the response was sent a number of times.
* Determine if a job was dispatched based on a truth-test callback.
*
* @param string $command
* @param int $times
* @param callable|null $callback
* @return void
*/
public function assertDispatchedAfterResponseTimes($command, $times = 1)
public function assertNotDispatched($command, $callback = null)
{
PHPUnit::assertTrue(
($count = $this->dispatchedAfterResponse($command)->count()) === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
$this->dispatched($command, $callback)->count() === 0 &&
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched."
);
}

/**
* Determine if a job was dispatched based on a truth-test callback.
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
*
* @param string $command
* @param callable|null $callback
* @param callable|int|null $callback
* @return void
*/
public function assertNotDispatched($command, $callback = null)
public function assertDispatchedAfterResponse($command, $callback = null)
{
if (is_numeric($callback)) {
return $this->assertDispatchedAfterResponseTimes($command, $callback);
}

PHPUnit::assertTrue(
$this->dispatched($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched."
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
"The expected [{$command}] job was not dispatched for after sending the response."
);
}

/**
* Determine if a job was dispatched based on a truth-test callback.
* Assert if a job was pushed after the response was sent a number of times.
*
* @param string $command
* @param callable|null $callback
* @param int $times
* @return void
*/
public function assertNotDispatchedAfterResponse($command, $callback = null)
public function assertDispatchedAfterResponseTimes($command, $times = 1)
{
PHPUnit::assertTrue(
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched for after sending the response."
($count = $this->dispatchedAfterResponse($command)->count()) === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
);
}

/**
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
* Determine if a job was dispatched based on a truth-test callback.
*
* @param string $command
* @param callable|int|null $callback
* @param callable|null $callback
* @return void
*/
public function assertDispatchedAfterResponse($command, $callback = null)
public function assertNotDispatchedAfterResponse($command, $callback = null)
{
if (is_numeric($callback)) {
return $this->assertDispatchedAfterResponseTimes($command, $callback);
}

PHPUnit::assertTrue(
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
"The expected [{$command}] job was not dispatched for after sending the response."
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched for after sending the response."
);
}

Expand Down

0 comments on commit e59597f

Please sign in to comment.