class AssertableJson implements Arrayable (View source)

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
$this
has(string $key, 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 $key)

Marks the property as interacted.

mixed
prop(string|null $key = null)

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

scope(string $key, Closure $callback)

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

etc()

Disables the interaction check.

first(Closure $callback)

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

where(string $key, mixed|Closure $expected)

Asserts that the property matches the expected value.

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

Asserts that the property does not match the expected value.

from  Matching
whereAll(array $bindings)

Asserts that all properties match their expected values.

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

Asserts that the property is of the expected type.

from  Matching
whereAllType(array $bindings)

Asserts that all properties are of their expected types.

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

Asserts that the property contains the expected values.

from  Matching
void
ensureSorted(mixed $value)

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

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

Dump the given arguments and terminate execution.

from  Dumpable
$this
dump(mixed ...$args)

Dump the given arguments.

from  Dumpable
void
interacted()

Asserts that all properties have been interacted with.

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

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

$this|TUnlessReturnType
unless($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, 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.

tap($callback = null)

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

from  Tappable
void
__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.

toArray()

Get the instance as an array.

Details

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

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

abstract $this has(string $key, null $value = null, Closure|null $scope = null)

Ensure that the given prop exists.

Parameters

string $key
null $value
Closure|null $scope

Return Value

$this

Has hasAll(array|string $key)

Assert that all of the given props exist.

Parameters

array|string $key

Return Value

Has

Has hasAny(array|string $key)

Assert that at least one of the given props exists.

Parameters

array|string $key

Return Value

Has

Has missingAll(array|string $key)

Assert that none of the given props exist.

Parameters

array|string $key

Return Value

Has

Has missing(string $key)

Assert that the given prop does not exist.

Parameters

string $key

Return Value

Has

protected string dotPath(string $key = '')

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

Parameters

string $key

Return Value

string

protected void interactsWith(string $key)

Marks the property as interacted.

Parameters

string $key

Return Value

void

protected mixed prop(string|null $key = null)

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

Parameters

string|null $key

Return Value

mixed

protected AssertableJson scope(string $key, Closure $callback)

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

Parameters

string $key
Closure $callback

Return Value

AssertableJson

Interaction etc()

Disables the interaction check.

Return Value

Interaction

AssertableJson first(Closure $callback)

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

Parameters

Closure $callback

Return Value

AssertableJson

Matching where(string $key, mixed|Closure $expected)

Asserts that the property matches the expected value.

Parameters

string $key
mixed|Closure $expected

Return Value

Matching

Matching whereNot(string $key, mixed|Closure $expected)

Asserts that the property does not match the expected value.

Parameters

string $key
mixed|Closure $expected

Return Value

Matching

Matching whereAll(array $bindings)

Asserts that all properties match their expected values.

Parameters

array $bindings

Return Value

Matching

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

Asserts that the property is of the expected type.

Parameters

string $key
string|array $expected

Return Value

Matching

Matching whereAllType(array $bindings)

Asserts that all properties are of their expected types.

Parameters

array $bindings

Return Value

Matching

$this whereContains(string $key, mixed $expected)

Asserts that the property contains the expected values.

Parameters

string $key
mixed $expected

Return Value

$this

protected void ensureSorted(mixed $value)

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

Parameters

mixed $value

Return Value

void

never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

$this dump(mixed ...$args)

Dump the given arguments.

Parameters

mixed ...$args

Return Value

$this

void interacted()

Asserts that all properties have been interacted with.

Return Value

void

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

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

Parameters

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

Return Value

$this|TWhenReturnType

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

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

Parameters

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

Return Value

$this|TUnlessReturnType

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

tap($callback = null)

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

Parameters

$callback

protected void __construct(array $props, string|null $path = null)

Create a new fluent, assertable JSON data instance.

Parameters

array $props
string|null $path

Return Value

void

AssertableJson each(Closure $callback)

Instantiate a new "scope" on each child element.

Parameters

Closure $callback

Return Value

AssertableJson

static AssertableJson fromArray(array $data)

Create a new instance from an array.

Parameters

array $data

Return Value

AssertableJson

static AssertableJson fromAssertableJsonString(AssertableJsonString $json)

Create a new instance from an AssertableJsonString.

Parameters

AssertableJsonString $json

Return Value

AssertableJson

toArray()

Get the instance as an array.