Skip to content

Commit

Permalink
fix bus fake
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 25, 2021
1 parent 4080566 commit e720279
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ public function assertChained(array $expectedChain)
if ($command instanceof Closure) {
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
} elseif (! is_string($command)) {
$command = get_class($command);
$instance = $command;

$command = get_class($instance);

$callback = function ($job) use ($instance) {
return serialize($this->resetChainPropertiesToDefaults($job)) === serialize($instance);
};
}

PHPUnit::assertTrue(
Expand All @@ -219,6 +225,22 @@ public function assertChained(array $expectedChain)
: $this->assertDispatchedWithChainOfClasses($command, $expectedChain, $callback);
}

/**
* Reset the chain properties to their default values on the job.
*
* @param mixed $job
* @return mixed
*/
protected function resetChainPropertiesToDefaults($job)
{
return tap(clone $job, function ($job) {
$job->chainConnection = null;
$job->chainQueue = null;
$job->chainCatchCallbacks = null;
$job->chained = [];
});
}

/**
* Assert if a job was dispatched with an empty chain based on a truth-test callback.
*
Expand Down

0 comments on commit e720279

Please sign in to comment.