Skip to content
Permalink
Browse files

adjust assertions

  • Loading branch information
taylorotwell committed Feb 10, 2020
1 parent 54ef968 commit e59597f13af3ee6e6467bdb8593844f9db6bb789
Showing with 31 additions and 26 deletions.
  1. +31 −26 src/Illuminate/Support/Testing/Fakes/BusFake.php
@@ -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."
);
}
@@ -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."
);
}

0 comments on commit e59597f

Please sign in to comment.
You can’t perform that action at this time.