AssertableJson
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
Assert that the prop is of the expected size.
Compose the absolute "dot" path to the given key.
Retrieve a prop within the current scope using "dot" notation.
Asserts that the property does not match the expected value.
Asserts that the property is of the expected type.
Asserts that all properties are of their expected types.
Asserts that the property contains the expected values.
Ensures 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.
Details
in
Has at line 18
Has
count(string|int $key, int|null $length = null)
Assert that the prop is of the expected size.
abstract $this
has(string $key, null $value = null, Closure|null $scope = null)
Ensure that the given prop exists.
in
Has at line 96
Has
hasAll(array|string $key)
Assert that all of the given props exist.
in
Has at line 117
Has
hasAny(array|string $key)
Assert that at least one of the given props exists.
in
Has at line 139
Has
missingAll(array|string $key)
Assert that none of the given props exist.
in
Has at line 156
Has
missing(string $key)
Assert that the given prop does not exist.
protected string
dotPath(string $key = '')
Compose the absolute "dot" path to the given key.
protected void
interactsWith(string $key)
Marks the property as interacted.
protected mixed
prop(string|null $key = null)
Retrieve a prop within the current scope using "dot" notation.
protected AssertableJson
scope(string $key, Closure $callback)
Instantiate a new "scope" at the path of the given key.
Interaction
etc()
Disables the interaction check.
AssertableJson
first(Closure $callback)
Instantiate a new "scope" on the first child element.
Matching
where(string $key, mixed|Closure $expected)
Asserts that the property matches the expected value.
Matching
whereNot(string $key, mixed|Closure $expected)
Asserts that the property does not match the expected value.
Matching
whereAll(array $bindings)
Asserts that all properties match their expected values.
Matching
whereType(string $key, string|array $expected)
Asserts that the property is of the expected type.
Matching
whereAllType(array $bindings)
Asserts that all properties are of their expected types.
$this
whereContains(string $key, mixed $expected)
Asserts that the property contains the expected values.
protected void
ensureSorted(mixed $value)
Ensures that all properties are sorted the same way, recursively.
Debugging
dump(string|null $prop = null)
Dumps the given props.
void
dd(string|null $prop = null)
Dumps the given props and exits.
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.
$this|HigherOrderTapProxy
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
protected void
__construct(array $props, string|null $path = null)
Create a new fluent, assertable JSON data instance.
AssertableJson
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.