class AssertableJson implements Arrayable

Traits

Properties

protected array $interacted

The list of interacted properties.

from  Interaction
static protected array $macros

The registered string macros.

from  Macroable

Methods

Has
count(string|int $key, int|null $length = null)

Assert that the prop is of the expected size.

from  Has
Has
countBetween(int|string $min, int|string $max)

Assert that the prop size is between a given minimum and maximum.

from  Has
has(string|int $key, int|Closure|null $value = null, Closure|null $scope = null)

Ensure that the given prop exists.

from  Matching
Has
hasAll(array|string $key)

Assert that all of the given props exist.

from  Has
Has
hasAny(array|string $key)

Assert that at least one of the given props exists.

from  Has
Has
missingAll(array|string $key)

Assert that none of the given props exist.

from  Has
Has
missing(string $key)

Assert that the given prop does not exist.

from  Has
string
dotPath(string $key = '')

Compose the absolute "dot" path to the given key.

void
interactsWith(string|int $key)

Mark the property as interacted.

mixed
prop(string|null $key = null)

Retrieve a prop within the current scope using "dot" notation.

scope(string|int $key, Closure $callback)

Instantiate a new "scope" at the path of the given key.

etc()

Disable the interaction check.

first(Closure $callback)

Instantiate a new "scope" on the first child element.

where(string $key, mixed $expected)

Assert that the property matches the expected value.

from  Matching
whereNot(string $key, mixed $expected)

Assert that the property does not match the expected value.

from  Matching
whereNull(string $key)

Assert that the property is null.

from  Matching
whereNotNull(string $key)

Assert that the property is not null.

from  Matching
whereAll(array $bindings)

Assert that all properties match their expected values.

from  Matching
whereType(string $key, array|string $expected)

Assert that the property is of the expected type.

from  Matching
whereAllType(array $bindings)

Assert that all properties are of their expected types.

from  Matching
whereContains(string $key, mixed $expected)

Assert that the property contains the expected values.

from  Matching
void
ensureSorted(mixed $value)

Ensure that all properties are sorted the same way, recursively.

from  Matching
never
dd(mixed ...$args)

Dump the given arguments and terminate execution.

from  Dumpable
dump(mixed ...$args)

Dump the given arguments.

from  Dumpable
void
interacted()

Assert that all properties have been interacted with.

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Check 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.

mixed
tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
__construct(array $props, string|null $path = null)

Create a new fluent, assertable JSON data instance.

each(Closure $callback)

Instantiate a new "scope" on each child element.

static AssertableJson
fromArray(array $data)

Create a new instance from an array.

static AssertableJson
fromAssertableJsonString(AssertableJsonString $json)

Create a new instance from an AssertableJsonString.

array
toArray()

Get the instance as an array.

static void
flushState()

Flush all static state.

Details

in Has at line 16
Has count(string|int $key, int|null $length = null)

Assert that the prop is of the expected size.

Parameters

string|int $key
int|null $length

Return Value

Has

in Has at line 44
Has countBetween(int|string $min, int|string $max)

Assert that the prop size is between a given minimum and maximum.

Parameters

int|string $min
int|string $max

Return Value

Has

in Matching at line 240
abstract Matching has(string|int $key, int|Closure|null $value = null, Closure|null $scope = null)

Ensure that the given prop exists.

Parameters

string|int $key
int|Closure|null $value
Closure|null $scope

Return Value

Matching

in Has at line 114
Has hasAll(array|string $key)

Assert that all of the given props exist.

Parameters

array|string $key

Return Value

Has

in Has at line 132
Has hasAny(array|string $key)

Assert that at least one of the given props exists.

Parameters

array|string $key

Return Value

Has

in Has at line 151
Has missingAll(array|string $key)

Assert that none of the given props exist.

Parameters

array|string $key

Return Value

Has

in Has at line 165
Has missing(string $key)

Assert that the given prop does not exist.

Parameters

string $key

Return Value

Has

at line 48
protected string dotPath(string $key = '')

Compose the absolute "dot" path to the given key.

Parameters

string $key

Return Value

string

in Interaction at line 20
protected void interactsWith(string|int $key)

Mark the property as interacted.

Parameters

string|int $key

Return Value

void

at line 60
protected mixed prop(string|null $key = null)

Retrieve a prop within the current scope using "dot" notation.

Parameters

string|null $key

Return Value

mixed

at line 68
protected AssertableJson scope(string|int $key, Closure $callback)

Instantiate a new "scope" at the path of the given key.

Parameters

string|int $key
Closure $callback

Return Value

AssertableJson

in Interaction at line 46
Interaction etc()

Disable the interaction check.

Return Value

Interaction

at line 85
AssertableJson first(Closure $callback)

Instantiate a new "scope" on the first child element.

Parameters

Closure $callback

Return Value

AssertableJson

in Matching at line 19
Matching where(string $key, mixed $expected)

Assert that the property matches the expected value.

Parameters

string $key
mixed $expected

Return Value

Matching

in Matching at line 53
Matching whereNot(string $key, mixed $expected)

Assert that the property does not match the expected value.

Parameters

string $key
mixed $expected

Return Value

Matching

in Matching at line 92
Matching whereNull(string $key)

Assert that the property is null.

Parameters

string $key

Return Value

Matching

in Matching at line 112
Matching whereNotNull(string $key)

Assert that the property is not null.

Parameters

string $key

Return Value

Matching

in Matching at line 132
Matching whereAll(array $bindings)

Assert that all properties match their expected values.

Parameters

array $bindings

Return Value

Matching

in Matching at line 144
Matching whereType(string $key, array|string $expected)

Assert that the property is of the expected type.

Parameters

string $key
array|string $expected

Return Value

Matching

in Matching at line 166
Matching whereAllType(array $bindings)

Assert that all properties are of their expected types.

Parameters

array $bindings

Return Value

Matching

in Matching at line 178
Matching whereContains(string $key, mixed $expected)

Assert that the property contains the expected values.

Parameters

string $key
mixed $expected

Return Value

Matching

in Matching at line 219
protected void ensureSorted(mixed $value)

Ensure that all properties are sorted the same way, recursively.

Parameters

mixed $value

Return Value

void

in Dumpable at line 12
never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

in Dumpable at line 20
Dumpable dump(mixed ...$args)

Dump the given arguments.

Parameters

mixed ...$args

Return Value

Dumpable

in Interaction at line 32
void interacted()

Assert that all properties have been interacted with.

Return Value

void

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Tappable at line 15
mixed tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

Parameters

callable|null $callback

Return Value

mixed

at line 39
protected __construct(array $props, string|null $path = null)

Create a new fluent, assertable JSON data instance.

Parameters

array $props
string|null $path

at line 108
AssertableJson each(Closure $callback)

Instantiate a new "scope" on each child element.

Parameters

Closure $callback

Return Value

AssertableJson

at line 133
static AssertableJson fromArray(array $data)

Create a new instance from an array.

Parameters

array $data

Return Value

AssertableJson

at line 141
static AssertableJson fromAssertableJsonString(AssertableJsonString $json)

Create a new instance from an AssertableJsonString.

Parameters

AssertableJsonString $json

Return Value

AssertableJson

at line 149
array toArray()

Get the instance as an array.

Return Value

array

at line 157
static void flushState()

Flush all static state.

Return Value

void