class Sleep (View source)

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 $while

The callback that determines if sleeping should continue.

protected int|float|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 then().

Methods

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

void
__construct(int|float|DateInterval $duration)

Create a new class instance.

static Sleep
for(DateInterval|int|float $duration)

Sleep for the given duration.

static Sleep
until(DateTimeInterface|int|float|numeric-string $timestamp)

Sleep until the given timestamp.

static Sleep
usleep(int $duration)

Sleep for the given number of microseconds.

static Sleep
sleep(int|float $duration)

Sleep for the given number of seconds.

$this
duration(DateInterval|int|float $duration)

Sleep for the given duration. Replaces any previously defined duration.

$this
minutes()

Sleep for the given number of minutes.

$this
minute()

Sleep for one minute.

$this
seconds()

Sleep for the given number of seconds.

$this
second()

Sleep for one second.

$this
milliseconds()

Sleep for the given number of milliseconds.

$this
millisecond()

Sleep for one millisecond.

$this
microseconds()

Sleep for the given number of microseconds.

$this
microsecond()

Sleep for on microsecond.

$this
and(int|float $duration)

Add additional time to sleep for.

$this
while(Closure $callback)

Sleep while a given callback returns "true".

mixed
then(callable $then)

Specify a callback that should be executed after sleeping.

void
__destruct()

Handle the object's destruction.

void
goodnight()

Handle the object's destruction.

int|float
pullPending()

Resolve the pending duration.

static void
fake(bool $value = true, bool $syncWithCarbon = false)

Stay awake and capture any attempts to sleep.

static void
assertSlept(Closure $expected, int $times = 1)

Assert a given amount of sleeping occurred a specific number of times.

static void
assertSleptTimes(int $expected)

Assert sleeping occurred a given number of times.

static void
assertSequence(array $sequence)

Assert the given sleep sequence was encountered.

static void
assertNeverSlept()

Assert that no sleeping occurred.

static void
assertInsomniac()

Assert that no sleeping occurred.

$this
shouldNotSleep()

Indicate that the instance should not sleep.

$this
when(Closure($this): bool|bool $condition)

Only sleep when the given condition is true.

$this
unless(Closure($this): bool|bool $condition)

Don't sleep when the given condition is true.

static void
whenFakingSleep(callable $callback)

Specify a callback that should be invoked when faking sleep within a test.

static void
syncWithCarbon($value = true)

Indicate that Carbon's "now" should be kept in sync when sleeping.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(int|float|DateInterval $duration)

Create a new class instance.

Parameters

int|float|DateInterval $duration

Return Value

void

static Sleep for(DateInterval|int|float $duration)

Sleep for the given duration.

Parameters

DateInterval|int|float $duration

Return Value

Sleep

static Sleep until(DateTimeInterface|int|float|numeric-string $timestamp)

Sleep until the given timestamp.

Parameters

DateTimeInterface|int|float|numeric-string $timestamp

Return Value

Sleep

static Sleep usleep(int $duration)

Sleep for the given number of microseconds.

Parameters

int $duration

Return Value

Sleep

static Sleep sleep(int|float $duration)

Sleep for the given number of seconds.

Parameters

int|float $duration

Return Value

Sleep

protected $this duration(DateInterval|int|float $duration)

Sleep for the given duration. Replaces any previously defined duration.

Parameters

DateInterval|int|float $duration

Return Value

$this

$this minutes()

Sleep for the given number of minutes.

Return Value

$this

$this minute()

Sleep for one minute.

Return Value

$this

$this seconds()

Sleep for the given number of seconds.

Return Value

$this

$this second()

Sleep for one second.

Return Value

$this

$this milliseconds()

Sleep for the given number of milliseconds.

Return Value

$this

$this millisecond()

Sleep for one millisecond.

Return Value

$this

$this microseconds()

Sleep for the given number of microseconds.

Return Value

$this

$this microsecond()

Sleep for on microsecond.

Return Value

$this

$this and(int|float $duration)

Add additional time to sleep for.

Parameters

int|float $duration

Return Value

$this

$this while(Closure $callback)

Sleep while a given callback returns "true".

Parameters

Closure $callback

Return Value

$this

mixed then(callable $then)

Specify a callback that should be executed after sleeping.

Parameters

callable $then

Return Value

mixed

void __destruct()

Handle the object's destruction.

Return Value

void

protected void goodnight()

Handle the object's destruction.

Return Value

void

protected int|float pullPending()

Resolve the pending duration.

Return Value

int|float

static void fake(bool $value = true, bool $syncWithCarbon = false)

Stay awake and capture any attempts to sleep.

Parameters

bool $value
bool $syncWithCarbon

Return Value

void

static void assertSlept(Closure $expected, int $times = 1)

Assert a given amount of sleeping occurred a specific number of times.

Parameters

Closure $expected
int $times

Return Value

void

static void assertSleptTimes(int $expected)

Assert sleeping occurred a given number of times.

Parameters

int $expected

Return Value

void

static void assertSequence(array $sequence)

Assert the given sleep sequence was encountered.

Parameters

array $sequence

Return Value

void

static void assertNeverSlept()

Assert that no sleeping occurred.

Return Value

void

static void assertInsomniac()

Assert that no sleeping occurred.

Return Value

void

protected $this shouldNotSleep()

Indicate that the instance should not sleep.

Return Value

$this

$this when(Closure($this): bool|bool $condition)

Only sleep when the given condition is true.

Parameters

Closure($this): bool|bool $condition

Return Value

$this

$this unless(Closure($this): bool|bool $condition)

Don't sleep when the given condition is true.

Parameters

Closure($this): bool|bool $condition

Return Value

$this

static void whenFakingSleep(callable $callback)

Specify a callback that should be invoked when faking sleep within a test.

Parameters

callable $callback

Return Value

void

static void syncWithCarbon($value = true)

Indicate that Carbon's "now" should be kept in sync when sleeping.

Parameters

$value

Return Value

void

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.