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 one microsecond.
Specify a callback that should be executed after sleeping.
Handle the object's destruction.
Sleep for the configured duration.
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 70
__construct(DateInterval|float|int $duration)
Create a new class instance.
at line 78
static Sleep
for(DateInterval|float|int $duration)
Sleep for the given duration.
at line 86
static Sleep
until(DateTimeInterface|float|int|string $timestamp)
Sleep until the given timestamp.
at line 98
static Sleep
usleep(int $duration)
Sleep for the given number of microseconds.
at line 106
static Sleep
sleep(float|int $duration)
Sleep for the given number of seconds.
at line 114
protected Sleep
duration(DateInterval|float|int $duration)
Sleep for the given duration. Replaces any previously defined duration.
at line 137
Sleep
minutes()
Sleep for the given number of minutes.
at line 148
Sleep
minute()
Sleep for one minute.
at line 156
Sleep
seconds()
Sleep for the given number of seconds.
at line 166
Sleep
second()
Sleep for one second.
at line 174
Sleep
milliseconds()
Sleep for the given number of milliseconds.
at line 184
Sleep
millisecond()
Sleep for one millisecond.
at line 192
Sleep
microseconds()
Sleep for the given number of microseconds.
at line 202
Sleep
microsecond()
Sleep for one microsecond.
at line 210
Sleep
and(float|int $duration)
Add additional time to sleep for.
at line 230
mixed
then(callable $then)
Specify a callback that should be executed after sleeping.
at line 245
__destruct()
Handle the object's destruction.
at line 255
protected void
goodnight()
Sleep for the configured duration.
at line 308
protected float|int
pullPending()
Resolve the pending duration.
at line 331
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 343
static void
assertSlept(Closure $expected, int $times = 1)
Assert a given amount of sleeping occurred a specific number of times.
at line 357
static void
assertSleptTimes(int $expected)
Assert sleeping occurred a given number of times.
at line 365
static void
assertSequence(array $sequence)
Assert the given sleep sequence was encountered.
at line 403
static void
assertNeverSlept()
Assert that no sleeping occurred.
at line 411
static void
assertInsomniac()
Assert that no sleeping occurred.
at line 430
protected Sleep
shouldNotSleep()
Indicate that the instance should not sleep.
at line 461
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 472
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 480
static void
flushState()
Flush all static state.