QueueFake
class QueueFake extends QueueManager implements Fake, Queue
Traits
Hosts must declare a protected array $poolableDrivers containing their default poolable drivers.
Properties
| protected Closure> | $releaseCallbacks | from HasPoolProxy | |
| protected array | $connections | The array of resolved queue connections. |
from QueueManager |
| protected array | $connectors | The array of resolved queue connectors. |
from QueueManager |
| protected array | $poolableDrivers | The array of drivers which will be wrapped as pool proxies. |
from QueueManager |
| protected QueuePoolProxy>> | $poolProxyClasses | The pool proxy classes for drivers with supplemental queue capabilities. |
from QueueManager |
| Factory|null | $queue | The original queue manager. |
|
| protected Collection | $jobsToFake | The job types that should be intercepted instead of pushed to the queue. |
|
| protected Collection | $jobsToBeQueued | The job types that should be pushed to the queue and not intercepted. |
|
| protected array | $jobs | All of the jobs that have been pushed. |
|
| protected RawPushType> | $rawPushes | All of the payloads that have been raw pushed. |
|
| protected LockSnapshot> | $dispatchLocks | The dispatch locks owned by faked jobs. |
|
| protected array | $reserved | All of the jobs that have been marked as reserved. |
|
| protected bool | $serializeAndRestore | Indicates if items should be serialized and restored when pushed to the queue. |
|
| protected array<int, callable> | $beforePushingCallbacks | The callbacks that should be invoked before pushing a job. |
|
| protected array<int, callable> | $afterPushingCallbacks | The callbacks that should be invoked after pushing a job. |
Methods
Create a pool proxy for an immutable definition.
Build a namespaced pool definition for a pooled resource.
Get the release callback for a pooled driver.
Add a driver to the poolable-driver list.
Remove a driver from the poolable-driver list.
Set the poolable-driver list.
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Resolve the default connection name for a given queueable instance.
Resolve the default queue name for a given queueable instance.
Get the container that owns the queue routes.
Create a new fake queue instance.
Register an event listener for the exception occurred job event.
Register an event listener for the daemon queue loop.
Register an event listener for the failed job event.
Register an event listener for the daemon queue starting.
Register an event listener for the daemon queue stopping.
Register a callback to be invoked when a job runs for longer than a given amount of time.
Register the default queue route for a given class.
Forward the given queue to another queue and/or connection.
Pause a queue by its name and connection.
Pause a queue by its name and connection for a given amount of time.
Resume a paused queue by its name and connection.
Determine if a queue is paused.
Determine which of the given queues are currently paused.
Indicate that queue workers should not poll for restart or pause signals.
Determine if the driver is connected.
Resolve a queue connection instance.
Reject circular definitions owned by the resolved failover connector.
Get the connector for a given driver.
Set the name of the default queue connection.
Get the full name for the given connection.
Disconnect a queue connection and close its shared resource pool.
Register a callback to be executed when creating job payloads.
Override the QueueManager to prevent circular dependency.
Resolve a truth-test callback or an array of expected properties.
Get a configuration value from an attribute, falling back to a property.
Extract the value from an attribute instance.
Get an instance of the given attribute class from the target class or its parents.
Determine if a property declared on a child class overrides an inherited attribute.
Get the class name of the first parameter of the given Closure.
Get the class names of the first parameter of the given Closure, including union types.
Get the class names / types of the parameters of the given Closure.
Get the class names / types of the return type of the given Closure.
Specify the jobs that should be queued instead of faked.
Assert if a job was pushed based on a truth-test callback.
Assert if a job was pushed a number of times.
Assert if a job was pushed exactly once.
Assert if a job was pushed based on a truth-test callback.
Assert if a job was pushed with chained jobs based on a truth-test callback.
Assert if a job was pushed with an empty chain based on a truth-test callback.
Assert if a job was pushed with chained jobs based on a truth-test callback.
Assert if a job was pushed with chained jobs based on a truth-test callback.
Assert if a closure was pushed based on a truth-test callback.
Assert that a closure was not pushed based on a truth-test callback.
Determine if the given chain is entirely composed of objects.
Determine if a job was pushed based on a truth-test callback.
Assert the total count of jobs that were pushed.
Assert that no jobs were pushed.
Get all of the jobs matching a truth-test callback.
Get all of the jobs by listener class, passing an optional truth-test callback.
Determine if there are any stored jobs for a given class.
Get the size of the queue.
Get the number of pending jobs.
Get the number of delayed jobs.
Get the number of reserved jobs.
Get the number of jobs across every queue.
Get the number of pending jobs across every queue.
Get the number of delayed jobs across every queue.
Get the number of reserved jobs across every queue.
Get the pending jobs for the given queue.
Get the delayed jobs for the given queue.
Get the reserved jobs for the given queue.
Get all pending jobs across every queue.
Get all delayed jobs across every queue.
Map an array of jobs to a collection of inspected jobs.
Get all reserved jobs across every queue.
Get pushed jobs classified by their delay.
Get the creation timestamp of the oldest pending job, excluding delayed jobs.
Push a new job onto the queue.
Push a job onto the fake, or onto the given connection when the job is not faked.
Determine if a job should be faked or actually dispatched.
Determine if a job should be pushed to the queue instead of faked.
Push a raw payload onto the queue.
Push a new job onto the queue after (n) seconds.
Push a new job onto the queue.
Push a new job onto a specific queue after (n) seconds.
Record the given job as reserved.
Push an array of jobs onto the queue.
Push an array of jobs onto the fake, or onto the given connection for jobs that are not faked.
Get the jobs that have been pushed.
Get the payloads that were pushed raw.
Specify if jobs should be serialized and restored when being "pushed" to the queue.
Serialize and unserialize the job to simulate the queueing process.
Release the dispatch locks owned by faked jobs.
Clear all of the reserved jobs.
Register a callback to be invoked before pushing a job.
Register a callback to be invoked after pushing a job.
Normalize a queue identifier.
Get the connection name for the queue.
Set the connection name for the queue.
Details
in
HasPoolProxy at line 28
protected mixed
createPoolProxy(string $driver, Closure $createCallback, PoolDefinition $definition, string $proxyClass)
Create a pool proxy for an immutable definition.
in
HasPoolProxy at line 49
protected PoolDefinition
poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)
Build a namespaced pool definition for a pooled resource.
in
HasPoolProxy at line 67
abstract protected Factory
poolFactory()
Get the pool factory used by this manager.
in
HasPoolProxy at line 75
HasPoolProxy
setReleaseCallback(string $driver, Closure $callback)
Set the release callback for a pooled driver.
The callback persists on the shared manager for the worker lifetime and is captured by every subsequently created proxy for the driver.
in
HasPoolProxy at line 86
Closure|null
getReleaseCallback(string $driver)
Get the release callback for a pooled driver.
in
HasPoolProxy at line 98
HasPoolProxy
addPoolableDriver(string $driver)
Add a driver to the poolable-driver list.
The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.
in
HasPoolProxy at line 115
HasPoolProxy
removePoolableDriver(string $driver)
Remove a driver from the poolable-driver list.
The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.
in
HasPoolProxy at line 133
array
getPoolableDrivers()
Get the poolable-driver list.
in
HasPoolProxy at line 145
HasPoolProxy
setPoolableDrivers(array $poolableDrivers)
Set the poolable-driver list.
The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.
in
InteractsWithTime at line 17
protected int
secondsUntil(DateInterval|DateTimeInterface|int $delay)
Get the number of seconds until the given DateTime.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
in
InteractsWithTime at line 47
protected DateTimeInterface|int
parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)
If the given value is an interval, convert it to a DateTime instance.
in
InteractsWithTime at line 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 71
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
in
ResolvesQueueRoutes at line 19
string|null
resolveConnectionFromQueueRoute(object $queueable, UnitEnum|string|null $queue = null)
Resolve the default connection name for a given queueable instance.
in
ResolvesQueueRoutes at line 27
string|null
resolveQueueFromQueueRoute(object $queueable)
Resolve the default queue name for a given queueable instance.
in
ResolvesQueueRoutes at line 35
protected QueueRoutes
queueRoutes()
Get the queue routes manager instance.
in
ResolvesQueueRoutes at line 48
protected Container
queueRoutesContainer()
Get the container that owns the queue routes.
at line 103
__construct(Container $app, array|string $jobsToFake = [], Factory|null $queue = null)
Create a new fake queue instance.
in
QueueManager at line 95
void
before(mixed $callback)
Register an event listener for the before job event.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 108
void
after(mixed $callback)
Register an event listener for the after job event.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 121
void
exceptionOccurred(mixed $callback)
Register an event listener for the exception occurred job event.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 134
void
looping(mixed $callback)
Register an event listener for the daemon queue loop.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 147
void
failing(mixed $callback)
Register an event listener for the failed job event.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 160
void
starting(mixed $callback)
Register an event listener for the daemon queue starting.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 173
void
stopping(mixed $callback)
Register an event listener for the daemon queue stopping.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 186
void
whenJobRunsLongerThan(DateTimeInterface|CarbonInterval|float|int $threshold, callable $handler)
Register a callback to be invoked when a job runs for longer than a given amount of time.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent matching queue event.
in
QueueManager at line 214
void
route(array|string $class, UnitEnum|string|null $queue = null, UnitEnum|string|null $connection = null)
Register the default queue route for a given class.
The route persists on the singleton QueueRoutes registry for the worker lifetime and affects every subsequent dispatch of that class.
in
QueueManager at line 228
void
forward(array|string|UnitEnum $queue, UnitEnum|string|null $to = null, UnitEnum|string|null $connection = null)
Forward the given queue to another queue and/or connection.
Forwards persist on the singleton QueueRoutes registry for the worker lifetime and affect every subsequent dispatch and queue operation.
in
QueueManager at line 245
void
pause(UnitEnum|string $queue, UnitEnum|string|null $connection = null)
Pause a queue by its name and connection.
in
QueueManager at line 267
void
pauseFor(UnitEnum|string $queue, DateInterval|DateTimeInterface|int $ttl, UnitEnum|string|null $connection = null)
Pause a queue by its name and connection for a given amount of time.
in
QueueManager at line 289
void
pauseAll()
Pause job processing for all queues on all connections.
in
QueueManager at line 307
void
resume(UnitEnum|string $queue, UnitEnum|string|null $connection = null)
Resume a paused queue by its name and connection.
in
QueueManager at line 331
void
resumeAll()
Resume job processing for all queues on all connections.
Queues paused individually are not affected.
in
QueueManager at line 349
bool
isPaused(UnitEnum|string $queue, UnitEnum|string|null $connection = null)
Determine if a queue is paused.
in
QueueManager at line 365
array
getPausedQueues(array $queues, string|null $connection = null)
Determine which of the given queues are currently paused.
in
QueueManager at line 398
void
withoutInterruptionPolling()
Indicate that queue workers should not poll for restart or pause signals.
This prevents the workers from hitting the application cache to determine if they need to pause or restart.
Mutates process-global worker flags; runtime use races across coroutines and changes every concurrent worker pause or restart check.
in
QueueManager at line 408
bool
connected(UnitEnum|string|null $name = null)
Determine if the driver is connected.
at line 405
Queue
connection(UnitEnum|string|null $value = null)
Resolve a queue connection instance.
in
QueueManager at line 449
protected Queue
resolve(string $name)
Resolve a queue connection.
in
QueueManager at line 490
protected void
ensureConnectionsAreAcyclic(array $config, string $driver, array $path = [])
Reject circular definitions owned by the resolved failover connector.
in
QueueManager at line 523
protected ConnectorInterface
getConnector(string $driver)
Get the connector for a given driver.
in
QueueManager at line 538
void
extend(string $driver, Closure $resolver)
Add a queue connection resolver.
The resolver persists in the singleton's connectors array for the worker lifetime and applies to every subsequent connection.
in
QueueManager at line 550
void
addConnector(string $driver, Closure $resolver)
Add a queue connection resolver.
The resolver persists in the singleton's connectors array for the worker lifetime and applies to every subsequent connection.
in
QueueManager at line 559
protected array|null
getConfig(string $name)
Get the queue connection configuration.
in
QueueManager at line 579
string
getDefaultDriver()
Get the name of the default queue connection.
in
QueueManager at line 589
void
setDefaultDriver(UnitEnum|string $name)
Set the name of the default queue connection.
Mutates process-global config; per-request use races across coroutines.
in
QueueManager at line 600
string
getName(string|null $connection = null)
Get the full name for the given connection.
in
QueueManager at line 613
void
purge(string|null $name = null)
Disconnect a queue connection and close its shared resource pool.
Use this to recover broken pooled resources. Other connections sharing the pool transparently acquire a fresh pool on their next operation.
in
QueueManager at line 649
Container
getApplication()
Get the application instance used by the manager.
in
QueueManager at line 663
QueueManager
setApplication(Container $app)
Set the application instance used by the manager.
Swaps the container reference on the singleton and on every cached queue connection; per-request use races across coroutines and breaks every concurrent dispatch.
in
QueueManager at line 689
void
createPayloadUsing(callable|null $callback)
Register a callback to be executed when creating job payloads.
The callback persists in a static property for the worker lifetime and runs on every subsequent payload creation across all coroutines. Passing null clears the registry.
at line 909
mixed
__call(string $method, array $parameters)
Override the QueueManager to prevent circular dependency.
in
MatchesProperties at line 19
protected callable|null
resolveTruthTest(callable|array|null $callback)
Resolve a truth-test callback or an array of expected properties.
in
ReadsClassAttributes at line 17
protected mixed
getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)
Get a configuration value from an attribute, falling back to a property.
in
ReadsClassAttributes at line 46
protected mixed
extractAttributeValue(object $instance)
Extract the value from an attribute instance.
in
ReadsClassAttributes at line 58
protected object|null
getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)
Get an instance of the given attribute class from the target class or its parents.
in
ReadsClassAttributes at line 74
protected bool
propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)
Determine if a property declared on a child class overrides an inherited attribute.
in
ReflectsClosures at line 26
protected string
firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
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.
in
ReflectsClosures at line 75
protected array
closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
in
ReflectsClosures at line 97
protected array
closureReturnTypes(Closure $closure)
Get the class names / types of the return type of the given Closure.
at line 117
QueueFake
except(array|string $jobsToBeQueued)
Specify the jobs that should be queued instead of faked.
at line 129
void
assertPushed(Closure|string $job, callable|array|int|null $callback = null)
Assert if a job was pushed based on a truth-test callback.
at line 149
void
assertPushedTimes(string $job, int $times = 1)
Assert if a job was pushed a number of times.
at line 167
void
assertPushedOnce(string $job)
Assert if a job was pushed exactly once.
at line 177
void
assertPushedOn(UnitEnum|string|null $queue, Closure|string $job, callable|array|null $callback = null)
Assert if a job was pushed based on a truth-test callback.
at line 204
void
assertPushedWithChain(string $job, array $expectedChain = [], callable|array|null $callback = null)
Assert if a job was pushed with chained jobs based on a truth-test callback.
at line 226
void
assertPushedWithoutChain(string $job, callable|array|null $callback = null)
Assert if a job was pushed with an empty chain based on a truth-test callback.
at line 241
protected void
assertPushedWithChainOfObjects(string $job, array $expectedChain, callable|array|null $callback)
Assert if a job was pushed with chained jobs based on a truth-test callback.
at line 256
protected void
assertPushedWithChainOfClasses(string $job, array $expectedChain, callable|array|null $callback)
Assert if a job was pushed with chained jobs based on a truth-test callback.
at line 275
void
assertClosurePushed(callable|array|int|null $callback = null)
Assert if a closure was pushed based on a truth-test callback.
at line 285
void
assertClosureNotPushed(callable|array|null $callback = null)
Assert that a closure was not pushed based on a truth-test callback.
at line 293
protected bool
isChainOfObjects(array $chain)
Determine if the given chain is entirely composed of objects.
at line 303
void
assertNotPushed(Closure|string $job, callable|array|null $callback = null)
Determine if a job was pushed based on a truth-test callback.
at line 319
void
assertCount(int $expectedCount)
Assert the total count of jobs that were pushed.
at line 333
void
assertNothingPushed()
Assert that no jobs were pushed.
at line 345
Collection
pushed(string $job, callable|array|null $callback = null)
Get all of the jobs matching a truth-test callback.
at line 364
Collection
pushedRaw(Closure|null $callback = null)
Get all of the raw pushes matching a truth-test callback.
at line 376
Collection
listenersPushed(string $listenerClass, callable|null $callback = null)
Get all of the jobs by listener class, passing an optional truth-test callback.
at line 397
bool
hasPushed(string $job)
Determine if there are any stored jobs for a given class.
at line 418
int
size(UnitEnum|string|null $queue = null)
Get the size of the queue.
at line 428
int
pendingSize(UnitEnum|string|null $queue = null)
Get the number of pending jobs.
at line 436
int
delayedSize(UnitEnum|string|null $queue = null)
Get the number of delayed jobs.
at line 444
int
reservedSize(UnitEnum|string|null $queue = null)
Get the number of reserved jobs.
at line 452
int
totalSize()
Get the number of jobs across every queue.
at line 462
int
totalPendingSize()
Get the number of pending jobs across every queue.
at line 470
int
totalDelayedSize()
Get the number of delayed jobs across every queue.
at line 478
int
totalReservedSize()
Get the number of reserved jobs across every queue.
at line 488
Collection
pendingJobs(UnitEnum|string|null $queue = null)
Get the pending jobs for the given queue.
at line 500
Collection
delayedJobs(UnitEnum|string|null $queue = null)
Get the delayed jobs for the given queue.
at line 512
Collection
reservedJobs(UnitEnum|string|null $queue = null)
Get the reserved jobs for the given queue.
at line 524
Collection
allPendingJobs()
Get all pending jobs across every queue.
at line 534
Collection
allDelayedJobs()
Get all delayed jobs across every queue.
at line 544
protected Collection
inspectJobs(array $jobs)
Map an array of jobs to a collection of inspected jobs.
at line 565
Collection
allReservedJobs()
Get all reserved jobs across every queue.
at line 573
protected array
pushedJobsWithDelay(bool $delayed)
Get pushed jobs classified by their delay.
at line 587
int|null
creationTimeOfOldestPendingJob(UnitEnum|string|null $queue = null)
Get the creation timestamp of the oldest pending job, excluding delayed jobs.
at line 598
mixed
push(object|string $job, mixed $data = '', UnitEnum|string|null $queue = null)
Push a new job onto the queue.
at line 610
mixed
pushToConnection(string|null $connection, object|string $job, mixed $data = '', UnitEnum|string|null $queue = null, DateInterval|DateTimeInterface|int|null $delay = null)
| internal |
Push a job onto the fake, or onto the given connection when the job is not faked.
Without a connection, a job that is not faked goes to its own connection, else the default connection.
at line 666
bool
shouldFakeJob(object|string $job)
Determine if a job should be faked or actually dispatched.
at line 684
protected bool
shouldDispatchJob(object|string $job)
Determine if a job should be pushed to the queue instead of faked.
at line 698
mixed
pushRaw(string $payload, UnitEnum|string|null $queue = null, array $options = [])
Push a raw payload onto the queue.
at line 712
mixed
later(DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '', UnitEnum|string|null $queue = null)
Push a new job onto the queue after (n) seconds.
at line 724
mixed
pushOn(UnitEnum|string|null $queue, object|string $job, mixed $data = '')
Push a new job onto the queue.
at line 732
mixed
laterOn(UnitEnum|string|null $queue, DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '')
Push a new job onto a specific queue after (n) seconds.
at line 744
void
reserve(object|string $job, UnitEnum|string|null $queue = null)
Record the given job as reserved.
at line 763
Job|null
pop(UnitEnum|string|null $queue = null)
Pop the next job off of the queue.
at line 771
mixed
bulk(array $jobs, mixed $data = '', UnitEnum|string|null $queue = null)
Push an array of jobs onto the queue.
at line 781
mixed
bulkToConnection(string|null $connection, array $jobs, mixed $data = '', UnitEnum|string|null $queue = null)
| internal |
Push an array of jobs onto the fake, or onto the given connection for jobs that are not faked.
at line 799
array
pushedJobs()
Get the jobs that have been pushed.
at line 809
array
rawPushes()
Get the payloads that were pushed raw.
at line 819
QueueFake
serializeAndRestore(bool $serializeAndRestore = true)
Specify if jobs should be serialized and restored when being "pushed" to the queue.
at line 829
protected mixed
serializeAndRestoreJob(mixed $job)
Serialize and unserialize the job to simulate the queueing process.
at line 837
void
releaseUniqueJobLocks()
Release the dispatch locks owned by faked jobs.
at line 849
void
clearReserved()
Clear all of the reserved jobs.
at line 859
QueueFake
beforePushing(callable $callback)
Register a callback to be invoked before pushing a job.
at line 871
QueueFake
afterPushing(callable $callback)
Register a callback to be invoked after pushing a job.
at line 881
protected string|null
normalizeQueue(UnitEnum|string|null $queue)
Normalize a queue identifier.
at line 889
string
getConnectionName()
Get the connection name for the queue.
at line 899
Queue
setConnectionName(string $name)
Set the connection name for the queue.