Sleep
class Sleep
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| static array | $fakeSleepCallbacks | The fake sleep callbacks. |
|
| static protected bool | $syncWithCarbon | Keep Carbon's "now" in sync when sleeping. |
|
| CarbonInterval | $duration | The total duration to sleep. |
|
| Closure|null | $while | The callback that determines if sleeping should continue. |
|
| protected float|int|null | $pending | The pending duration to sleep. |
|
| static protected bool | $fake | Indicates that all sleeping should be faked. |
|
| static protected CarbonInterval> | $sequence | The sequence of sleep durations encountered while faking. |
|
| protected bool | $shouldSleep | Indicates if the instance should sleep. |
|
| protected bool | $alreadySlept | Indicates if the instance already slept via |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Sleep for the given duration. Replaces any previously defined duration.
Sleep for the given number of milliseconds.
Sleep for one millisecond.
Sleep for the given number of microseconds.
Sleep for on microsecond.
Specify a callback that should be executed after sleeping.
Handle the object's destruction.
Handle the object's destruction.
Resolve the pending duration.
Stay awake and capture any attempts to sleep.
Assert a given amount of sleeping occurred a specific number of times.
Assert sleeping occurred a given number of times.
Assert the given sleep sequence was encountered.
Assert that no sleeping occurred.
Assert that no sleeping occurred.
Indicate that the instance should not sleep.
Specify a callback that should be invoked when faking sleep within a test.
Indicate that Carbon's "now" should be kept in sync when sleeping.
Flush all static state.
Details
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 72
__construct(DateInterval|float|int $duration)
Create a new class instance.
at line 80
static Sleep
for(DateInterval|float|int $duration)
Sleep for the given duration.
at line 88
static Sleep
until(DateTimeInterface|float|int|string $timestamp)
Sleep until the given timestamp.
at line 100
static Sleep
usleep(int $duration)
Sleep for the given number of microseconds.
at line 108
static Sleep
sleep(float|int $duration)
Sleep for the given number of seconds.
at line 116
protected Sleep
duration(DateInterval|float|int $duration)
Sleep for the given duration. Replaces any previously defined duration.
at line 139
Sleep
minutes()
Sleep for the given number of minutes.
at line 149
Sleep
minute()
Sleep for one minute.
at line 157
Sleep
seconds()
Sleep for the given number of seconds.
at line 167
Sleep
second()
Sleep for one second.
at line 175
Sleep
milliseconds()
Sleep for the given number of milliseconds.
at line 185
Sleep
millisecond()
Sleep for one millisecond.
at line 193
Sleep
microseconds()
Sleep for the given number of microseconds.
at line 203
Sleep
microsecond()
Sleep for on microsecond.
at line 211
Sleep
and(float|int $duration)
Add additional time to sleep for.
at line 231
mixed
then(callable $then)
Specify a callback that should be executed after sleeping.
at line 243
__destruct()
Handle the object's destruction.
at line 251
protected void
goodnight()
Handle the object's destruction.
at line 303
protected float|int
pullPending()
Resolve the pending duration.
at line 326
static void
fake(bool $value = true, bool $syncWithCarbon = false)
Stay awake and capture any attempts to sleep.
Tests only. Sleep fakes persist in static state for the worker lifetime and affect every subsequent sleep call.
at line 338
static void
assertSlept(Closure $expected, int $times = 1)
Assert a given amount of sleeping occurred a specific number of times.
at line 352
static void
assertSleptTimes(int $expected)
Assert sleeping occurred a given number of times.
at line 360
static void
assertSequence(array $sequence)
Assert the given sleep sequence was encountered.
at line 399
static void
assertNeverSlept()
Assert that no sleeping occurred.
at line 407
static void
assertInsomniac()
Assert that no sleeping occurred.
at line 426
protected Sleep
shouldNotSleep()
Indicate that the instance should not sleep.
at line 457
static void
whenFakingSleep(callable $callback)
Specify a callback that should be invoked when faking sleep within a test.
Tests only. The callback persists in static state for the worker lifetime and runs for every subsequent faked sleep.
at line 468
static void
syncWithCarbon(bool $value = true)
Indicate that Carbon's "now" should be kept in sync when sleeping.
Tests only. The flag persists in static state for the worker lifetime and affects every subsequent faked sleep.
at line 476
static void
flushState()
Flush all static state.