AssertableJson
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
Assert that the prop is of the expected size.
Assert that the prop size is between a given minimum and maximum.
Ensure that the given prop exists.
Compose the absolute "dot" path to the given key.
Retrieve a prop within the current scope using "dot" notation.
Assert that the property matches the expected value.
Assert that the property does not match the expected value.
Assert that the property is of the expected type.
Assert that all properties are of their expected types.
Assert that the property contains the expected values.
Ensure that all properties are sorted the same way, recursively.
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Call the given Closure with this instance then return the instance.
Create a new fluent, assertable JSON data instance.
Create a new instance from an array.
Create a new instance from an AssertableJsonString.
Get the instance as an array.
Flush all static state.
Details
in
Has at line 18
Has
count(string|int $key, int|null $length = null)
Assert that the prop is of the expected size.
in
Has at line 48
Has
countBetween(int|string $min, int|string $max)
Assert that the prop size is between a given minimum and maximum.
in
Matching at line 258
abstract Matching
has(string|int $key, int|Closure|null $value = null, Closure|null $scope = null)
Ensure that the given prop exists.
in
Has at line 142
Has
hasAny(array|string $key)
Assert that at least one of the given props exists.
at line 48
protected string
dotPath(string $key = '')
Compose the absolute "dot" path to the given key.
in
Interaction at line 20
protected void
interactsWith(string|int $key)
Mark the property as interacted.
at line 60
protected mixed
prop(string|null $key = null)
Retrieve a prop within the current scope using "dot" notation.
at line 70
protected AssertableJson
scope(string|int $key, Closure $callback)
Instantiate a new "scope" at the path of the given key.
in
Interaction at line 48
Interaction
etc()
Disable the interaction check.
at line 89
AssertableJson
first(Closure $callback)
Instantiate a new "scope" on the first child element.
in
Matching at line 21
Matching
where(string $key, mixed $expected)
Assert that the property matches the expected value.
in
Matching at line 57
Matching
whereNot(string $key, mixed $expected)
Assert that the property does not match the expected value.
in
Matching at line 142
Matching
whereAll(array $bindings)
Assert that all properties match their expected values.
in
Matching at line 156
Matching
whereType(string $key, array|string $expected)
Assert that the property is of the expected type.
in
Matching at line 180
Matching
whereAllType(array $bindings)
Assert that all properties are of their expected types.
in
Matching at line 194
Matching
whereContains(string $key, mixed $expected)
Assert that the property contains the expected values.
in
Matching at line 235
protected void
ensureSorted(mixed $value)
Ensure that all properties are sorted the same way, recursively.
in
Dumpable at line 12
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
in
Interaction at line 32
void
interacted()
Assert that all properties have been interacted with.
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.
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.
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.
in
Tappable at line 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 39
protected
__construct(array $props, string|null $path = null)
Create a new fluent, assertable JSON data instance.
at line 114
AssertableJson
each(Closure $callback)
Instantiate a new "scope" on each child element.
at line 139
static AssertableJson
fromArray(array $data)
Create a new instance from an array.
at line 147
static AssertableJson
fromAssertableJsonString(AssertableJsonString $json)
Create a new instance from an AssertableJsonString.
at line 155
array
toArray()
Get the instance as an array.
at line 163
static void
flushState()
Flush all static state.