class BusFake implements Fake, QueueingDispatcher

Traits

Properties

protected array $jobsToFake

The job types that should be intercepted instead of dispatched.

protected array $jobsToDispatch

The job types that should be dispatched instead of faked.

protected BatchRepository $batchRepository

The fake repository to track batched jobs.

protected array $commands

The commands that have been dispatched.

protected array $commandsSync

The commands that have been dispatched synchronously.

protected array $commandsAfterResponse

The commands that have been dispatched after the response has been sent.

protected array $batches

The batches that have been dispatched.

protected bool $serializeAndRestore

Indicates if commands should be serialized and restored when pushed to the Bus.

Methods

string
firstClosureParameterType(Closure $closure)

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

array
firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

array
closureParameterTypes(Closure $closure)

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

array
closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

__construct(QueueingDispatcher $dispatcher, array|string $jobsToFake = [], BatchRepository|null $batchRepository = null)

Create a new bus fake instance.

except(array|string $jobsToDispatch)

Specify the jobs that should be dispatched instead of faked.

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

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

void
assertDispatchedOnce(Closure|string $command)

Assert if a job was pushed exactly once.

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

Assert if a job was pushed a number of times.

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

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

void
assertNothingDispatched()

Assert that no jobs were dispatched.

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

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

void
assertDispatchedSyncTimes(Closure|string $command, int $times = 1)

Assert if a job was pushed synchronously a number of times.

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

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

void
assertDispatchedAfterResponse(Closure|string $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(Closure|string $command, int $times = 1)

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

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

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

void
assertChained(array $expectedChain)

Assert if a chain of jobs was dispatched.

void
assertNothingChained()

Assert no chained jobs was dispatched.

mixed
resetChainPropertiesToDefaults(mixed $job)

Reset the chain properties to their default values on the job.

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

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

void
assertDispatchedWithChainOfObjects(string $command, array $expectedChain, callable|null $callback)

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

chainedBatch(Closure $callback)

Create a new assertion about a chained batch.

void
assertBatched(callable|array $callback)

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

void
assertBatchCount(int $count)

Assert the number of batches that have been dispatched.

void
assertNothingBatched()

Assert that no batched jobs were dispatched.

void
assertNothingPlaced()

Assert that no jobs were dispatched, chained, or batched.

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

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

dispatchedSync(string $command, callable|null $callback = null)

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

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

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

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
hasDispatchedSync(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.

void
dispatchAfterResponse(mixed $command, mixed $handler = null)

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

void
bulk(iterable $jobs)

Dispatch multiple commands in bulk to their appropriate handlers on the queue.

mixed
chain(mixed $jobs = null)

Create a new chain of queueable jobs.

Batch|null
findBatch(string $batchId)

Attempt to find the batch with the given ID.

batch(mixed $jobs)

Create a new batch of queueable jobs.

dispatchFakeBatch(string $name = '')

Dispatch an empty job batch for testing.

recordPendingBatch(PendingBatch $pendingBatch)

Record the fake pending batch dispatch.

bool
shouldFakeJob(mixed $command)

Determine if a command should be faked or actually dispatched.

bool
shouldDispatchCommand(mixed $command)

Determine if a command should be dispatched or not.

serializeAndRestore(bool $serializeAndRestore = true)

Specify if commands should be serialized and restored when dispatched or batched.

mixed
serializeAndRestoreCommand(mixed $command)

Serialize and unserialize the command to simulate the queueing process.

mixed
getCommandRepresentation(mixed $command)

Return the command representation that should be stored.

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.

mixed
getCommandHandler(mixed $command)

Retrieve the handler for a command.

map(array $map)

Map a command to a handler.

array
dispatchedBatches()

Get the batches that have been dispatched.

Details

in ReflectsClosures at line 26
protected string firstClosureParameterType(Closure $closure)

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

Parameters

Closure $closure

Return Value

string

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 49
protected array firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 75
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

in ReflectsClosures at line 97
protected array closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

at line 71
__construct(QueueingDispatcher $dispatcher, array|string $jobsToFake = [], BatchRepository|null $batchRepository = null)

Create a new bus fake instance.

Parameters

QueueingDispatcher $dispatcher

the original Bus dispatcher implementation

array|string $jobsToFake
BatchRepository|null $batchRepository

at line 83
BusFake except(array|string $jobsToDispatch)

Specify the jobs that should be dispatched instead of faked.

Parameters

array|string $jobsToDispatch

Return Value

BusFake

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

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

Parameters

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

Return Value

void

at line 115
void assertDispatchedOnce(Closure|string $command)

Assert if a job was pushed exactly once.

Parameters

Closure|string $command

Return Value

void

at line 123
void assertDispatchedTimes(Closure|string $command, int $times = 1)

Assert if a job was pushed a number of times.

Parameters

Closure|string $command
int $times

Return Value

void

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

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

Parameters

Closure|string $command
callable|null $callback

Return Value

void

at line 166
void assertNothingDispatched()

Assert that no jobs were dispatched.

Return Value

void

at line 178
void assertDispatchedSync(Closure|string $command, callable|int|null $callback = null)

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

Parameters

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

Return Value

void

at line 198
void assertDispatchedSyncTimes(Closure|string $command, int $times = 1)

Assert if a job was pushed synchronously a number of times.

Parameters

Closure|string $command
int $times

Return Value

void

at line 222
void assertNotDispatchedSync(Closure|string $command, callable|null $callback = null)

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

Parameters

Closure|string $command
callable|null $callback

Return Value

void

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

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

Parameters

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

Return Value

void

at line 258
void assertDispatchedAfterResponseTimes(Closure|string $command, int $times = 1)

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

Parameters

Closure|string $command
int $times

Return Value

void

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

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

Parameters

Closure|string $command
callable|null $callback

Return Value

void

at line 298
void assertChained(array $expectedChain)

Assert if a chain of jobs was dispatched.

Parameters

array $expectedChain

Return Value

void

at line 335
void assertNothingChained()

Assert no chained jobs was dispatched.

Return Value

void

at line 343
protected mixed resetChainPropertiesToDefaults(mixed $job)

Reset the chain properties to their default values on the job.

Parameters

mixed $job

Return Value

mixed

at line 356
void assertDispatchedWithoutChain(Closure|string $command, callable|null $callback = null)

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

Parameters

Closure|string $command
callable|null $callback

Return Value

void

at line 375
protected void assertDispatchedWithChainOfObjects(string $command, array $expectedChain, callable|null $callback)

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

Parameters

string $command
array $expectedChain
callable|null $callback

Return Value

void

Exceptions

RuntimeException

at line 427
ChainedBatchTruthTest chainedBatch(Closure $callback)

Create a new assertion about a chained batch.

Parameters

Closure $callback

Return Value

ChainedBatchTruthTest

at line 437
void assertBatched(callable|array $callback)

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

Parameters

callable|array $callback

Return Value

void

at line 450
void assertBatchCount(int $count)

Assert the number of batches that have been dispatched.

Parameters

int $count

Return Value

void

at line 461
void assertNothingBatched()

Assert that no batched jobs were dispatched.

Return Value

void

at line 474
void assertNothingPlaced()

Assert that no jobs were dispatched, chained, or batched.

Return Value

void

at line 483
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

at line 497
Collection dispatchedSync(string $command, callable|null $callback = null)

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

Parameters

string $command
callable|null $callback

Return Value

Collection

at line 511
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

at line 528
Collection batched(callable $callback)

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

Parameters

callable $callback

Return Value

Collection

at line 540
bool hasDispatched(string $command)

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

Parameters

string $command

Return Value

bool

at line 548
bool hasDispatchedSync(string $command)

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

Parameters

string $command

Return Value

bool

at line 556
bool hasDispatchedAfterResponse(string $command)

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

Parameters

string $command

Return Value

bool

at line 564
mixed dispatch(mixed $command)

Dispatch a command to its appropriate handler.

Parameters

mixed $command

Return Value

mixed

at line 580
mixed dispatchSync(mixed $command, mixed $handler = null)

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

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

Parameters

mixed $command
mixed $handler

Return Value

mixed

at line 594
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

at line 608
mixed dispatchToQueue(mixed $command)

Dispatch a command to its appropriate handler behind a queue.

Parameters

mixed $command

Return Value

mixed

at line 622
void dispatchAfterResponse(mixed $command, mixed $handler = null)

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

Parameters

mixed $command
mixed $handler

Return Value

void

at line 635
void bulk(iterable $jobs)

Dispatch multiple commands in bulk to their appropriate handlers on the queue.

Parameters

iterable $jobs

Return Value

void

at line 645
mixed chain(mixed $jobs = null)

Create a new chain of queueable jobs.

Parameters

mixed $jobs

Return Value

mixed

at line 656
Batch|null findBatch(string $batchId)

Attempt to find the batch with the given ID.

Parameters

string $batchId

Return Value

Batch|null

at line 664
PendingBatch batch(mixed $jobs)

Create a new batch of queueable jobs.

Parameters

mixed $jobs

Return Value

PendingBatch

at line 672
Batch dispatchFakeBatch(string $name = '')

Dispatch an empty job batch for testing.

Parameters

string $name

Return Value

Batch

at line 680
Batch recordPendingBatch(PendingBatch $pendingBatch)

Record the fake pending batch dispatch.

Parameters

PendingBatch $pendingBatch

Return Value

Batch

at line 696
protected bool shouldFakeJob(mixed $command)

Determine if a command should be faked or actually dispatched.

Parameters

mixed $command

Return Value

bool

at line 717
protected bool shouldDispatchCommand(mixed $command)

Determine if a command should be dispatched or not.

Parameters

mixed $command

Return Value

bool

at line 730
BusFake serializeAndRestore(bool $serializeAndRestore = true)

Specify if commands should be serialized and restored when dispatched or batched.

Parameters

bool $serializeAndRestore

Return Value

BusFake

at line 740
protected mixed serializeAndRestoreCommand(mixed $command)

Serialize and unserialize the command to simulate the queueing process.

Parameters

mixed $command

Return Value

mixed

at line 748
protected mixed getCommandRepresentation(mixed $command)

Return the command representation that should be stored.

Parameters

mixed $command

Return Value

mixed

at line 756
Dispatcher pipeThrough(array $pipes)

Set the pipes commands should be piped through before dispatching.

Parameters

array $pipes

Return Value

Dispatcher

at line 766
bool hasCommandHandler(mixed $command)

Determine if the given command has a handler.

Parameters

mixed $command

Return Value

bool

at line 774
mixed getCommandHandler(mixed $command)

Retrieve the handler for a command.

Parameters

mixed $command

Return Value

mixed

at line 782
Dispatcher map(array $map)

Map a command to a handler.

Parameters

array $map

Return Value

Dispatcher

at line 792
array dispatchedBatches()

Get the batches that have been dispatched.

Return Value

array