W3cubDocs

/Laravel 8

BusFake

class BusFake implements QueueingDispatcher (View source)

Traits

ReflectsClosures

Properties

protected QueueingDispatcher $dispatcher The original Bus dispatcher implementation.
protected array $jobsToFake The job types that should be intercepted instead of dispatched.
protected array $commands The commands that have been dispatched.
protected array $commandsAfterResponse The commands that have been dispatched after the response has been sent.
protected array $batches The batches that have been dispatched.

Methods

array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

from ReflectsClosures
string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

from ReflectsClosures
void __construct(QueueingDispatcher $dispatcher, array|string $jobsToFake = [])

Create a new bus fake instance.

void assertDispatched(string|Closure $command, callable|int|null $callback = null)

Assert if a job was dispatched based on a truth-test callback.

void assertDispatchedTimes(string $command, int $times = 1)

Assert if a job was pushed a number of times.

void assertNotDispatched(string|Closure $command, callable|null $callback = null)

Determine if a job was dispatched based on a truth-test callback.

void assertDispatchedAfterResponse(string|Closure $command, callable|int|null $callback = null)

Assert if a job was dispatched after the response was sent based on a truth-test callback.

void assertDispatchedAfterResponseTimes(string $command, int $times = 1)

Assert if a job was pushed after the response was sent a number of times.

void assertNotDispatchedAfterResponse(string|Closure $command, callable|null $callback = null)

Determine if a job was dispatched based on a truth-test callback.

void assertBatched(callable $callback)

Assert if a batch was dispatched based on a truth-test callback.

Collection dispatched(string $command, callable|null $callback = null)

Get all of the jobs matching a truth-test callback.

Collection dispatchedAfterResponse(string $command, callable|null $callback = null)

Get all of the jobs dispatched after the response was sent matching a truth-test callback.

Collection batched(callable $callback)

Get all of the pending batches matching a truth-test callback.

bool hasDispatched(string $command)

Determine if there are any stored commands for a given class.

bool hasDispatchedAfterResponse(string $command)

Determine if there are any stored commands for a given class.

mixed dispatch(mixed $command)

Dispatch a command to its appropriate handler.

mixed dispatchSync(mixed $command, mixed $handler = null)

Dispatch a command to its appropriate handler in the current process.

mixed dispatchNow(mixed $command, mixed $handler = null)

Dispatch a command to its appropriate handler in the current process.

mixed dispatchToQueue(mixed $command)

Dispatch a command to its appropriate handler behind a queue.

mixed dispatchAfterResponse(mixed $command)

Dispatch a command to its appropriate handler.

PendingChain chain(Collection|array $jobs)

Create a new chain of queueable jobs.

Batch|null findBatch(string $batchId)

Attempt to find the batch with the given ID.

PendingBatch batch(Collection|array $jobs)

Create a new batch of queueable jobs.

Batch recordPendingBatch(PendingBatch $pendingBatch)

Record the fake pending batch dispatch.

bool shouldFakeJob(mixed $command)

Determine if an command should be faked or actually dispatched.

$this pipeThrough(array $pipes)

Set the pipes commands should be piped through before dispatching.

bool hasCommandHandler(mixed $command)

Determine if the given command has a handler.

bool|mixed getCommandHandler(mixed $command)

Retrieve the handler for a command.

$this map(array $map)

Map a command to a handler.

Details

protected array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

protected string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

Parameters

Closure $closure

Return Value

string

Exceptions

RuntimeException

void __construct(QueueingDispatcher $dispatcher, array|string $jobsToFake = [])

Create a new bus fake instance.

Parameters

QueueingDispatcher $dispatcher
array|string $jobsToFake

Return Value

void

void assertDispatched(string|Closure $command, callable|int|null $callback = null)

Assert if a job was dispatched based on a truth-test callback.

Parameters

string|Closure $command
callable|int|null $callback

Return Value

void

void assertDispatchedTimes(string $command, int $times = 1)

Assert if a job was pushed a number of times.

Parameters

string $command
int $times

Return Value

void

void assertNotDispatched(string|Closure $command, callable|null $callback = null)

Determine if a job was dispatched based on a truth-test callback.

Parameters

string|Closure $command
callable|null $callback

Return Value

void

void assertDispatchedAfterResponse(string|Closure $command, callable|int|null $callback = null)

Assert if a job was dispatched after the response was sent based on a truth-test callback.

Parameters

string|Closure $command
callable|int|null $callback

Return Value

void

void assertDispatchedAfterResponseTimes(string $command, int $times = 1)

Assert if a job was pushed after the response was sent a number of times.

Parameters

string $command
int $times

Return Value

void

void assertNotDispatchedAfterResponse(string|Closure $command, callable|null $callback = null)

Determine if a job was dispatched based on a truth-test callback.

Parameters

string|Closure $command
callable|null $callback

Return Value

void

void assertBatched(callable $callback)

Assert if a batch was dispatched based on a truth-test callback.

Parameters

callable $callback

Return Value

void

Collection dispatched(string $command, callable|null $callback = null)

Get all of the jobs matching a truth-test callback.

Parameters

string $command
callable|null $callback

Return Value

Collection

Collection dispatchedAfterResponse(string $command, callable|null $callback = null)

Get all of the jobs dispatched after the response was sent matching a truth-test callback.

Parameters

string $command
callable|null $callback

Return Value

Collection

Collection batched(callable $callback)

Get all of the pending batches matching a truth-test callback.

Parameters

callable $callback

Return Value

Collection

bool hasDispatched(string $command)

Determine if there are any stored commands for a given class.

Parameters

string $command

Return Value

bool

bool hasDispatchedAfterResponse(string $command)

Determine if there are any stored commands for a given class.

Parameters

string $command

Return Value

bool

mixed dispatch(mixed $command)

Dispatch a command to its appropriate handler.

Parameters

mixed $command

Return Value

mixed

mixed dispatchSync(mixed $command, mixed $handler = null)

Dispatch a command to its appropriate handler in the current process.

Queuable jobs will be dispatched to the "sync" queue.

Parameters

mixed $command
mixed $handler

Return Value

mixed

mixed dispatchNow(mixed $command, mixed $handler = null)

Dispatch a command to its appropriate handler in the current process.

Parameters

mixed $command
mixed $handler

Return Value

mixed

mixed dispatchToQueue(mixed $command)

Dispatch a command to its appropriate handler behind a queue.

Parameters

mixed $command

Return Value

mixed

mixed dispatchAfterResponse(mixed $command)

Dispatch a command to its appropriate handler.

Parameters

mixed $command

Return Value

mixed

PendingChain chain(Collection|array $jobs)

Create a new chain of queueable jobs.

Parameters

Collection|array $jobs

Return Value

PendingChain

Batch|null findBatch(string $batchId)

Attempt to find the batch with the given ID.

Parameters

string $batchId

Return Value

Batch|null

PendingBatch batch(Collection|array $jobs)

Create a new batch of queueable jobs.

Parameters

Collection|array $jobs

Return Value

PendingBatch

Batch recordPendingBatch(PendingBatch $pendingBatch)

Record the fake pending batch dispatch.

Parameters

PendingBatch $pendingBatch

Return Value

Batch

protected bool shouldFakeJob(mixed $command)

Determine if an command should be faked or actually dispatched.

Parameters

mixed $command

Return Value

bool

$this pipeThrough(array $pipes)

Set the pipes commands should be piped through before dispatching.

Parameters

array $pipes

Return Value

$this

bool hasCommandHandler(mixed $command)

Determine if the given command has a handler.

Parameters

mixed $command

Return Value

bool

bool|mixed getCommandHandler(mixed $command)

Retrieve the handler for a command.

Parameters

mixed $command

Return Value

bool|mixed

$this map(array $map)

Map a command to a handler.

Parameters

array $map

Return Value

$this

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Support/Testing/Fakes/BusFake.html