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 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 71
__construct(DateInterval|float|int $duration)
Create a new class instance.
at line 79
static Sleep
for(DateInterval|float|int $duration)
Sleep for the given duration.
at line 87
static Sleep
until(DateTimeInterface|float|int|string $timestamp)
Sleep until the given timestamp.
at line 99
static Sleep
usleep(int $duration)
Sleep for the given number of microseconds.
at line 107
static Sleep
sleep(float|int $duration)
Sleep for the given number of seconds.
at line 117
protected Sleep
duration(DateInterval|float|int $duration)
Sleep for the given duration. Replaces any previously defined duration.
at line 142
Sleep
minutes()
Sleep for the given number of minutes.
at line 155
Sleep
minute()
Sleep for one minute.
at line 165
Sleep
seconds()
Sleep for the given number of seconds.
at line 177
Sleep
second()
Sleep for one second.
at line 187
Sleep
milliseconds()
Sleep for the given number of milliseconds.
at line 199
Sleep
millisecond()
Sleep for one millisecond.
at line 209
Sleep
microseconds()
Sleep for the given number of microseconds.
at line 221
Sleep
microsecond()
Sleep for one microsecond.
at line 231
Sleep
and(float|int $duration)
Add additional time to sleep for.
at line 253
mixed
then(callable $then)
Specify a callback that should be executed after sleeping.
at line 268
__destruct()
Handle the object's destruction.
at line 278
protected void
goodnight()
Sleep for the configured duration.
at line 333
protected float|int
pullPending()
Resolve the pending duration.
at line 356
static void
fake(bool $value = true, bool $syncWithCarbon = false)
Stay awake and capture any attempts to sleep.
Sleep fakes persist in static state for the worker lifetime and affect every subsequent sleep call.
at line 369
static void
assertSlept(Closure $expected, int $times = 1)
Assert a given amount of sleeping occurred a specific number of times.
at line 383
static void
assertSleptTimes(int $expected)
Assert sleeping occurred a given number of times.
at line 391
static void
assertSequence(array $sequence)
Assert the given sleep sequence was encountered.
at line 429
static void
assertNeverSlept()
Assert that no sleeping occurred.
at line 437
static void
assertInsomniac()
Assert that no sleeping occurred.
at line 458
protected Sleep
shouldNotSleep()
Indicate that the instance should not sleep.
at line 493
static void
whenFakingSleep(callable $callback)
Specify a callback that should be invoked when faking sleep within a test.
The callback persists in static state for the worker lifetime and runs for every subsequent faked sleep.
at line 505
static void
syncWithCarbon(bool $value = true)
Indicate that Carbon's "now" should be kept in sync when sleeping.
The flag persists in static state for the worker lifetime and affects every subsequent faked sleep.
at line 514
static void
flushState()
Flush all static state.