AssertableJson
class AssertableJson implements Arrayable (View source)
Traits
Has | |
Matching | |
Debugging | |
Interaction | |
Macroable | |
Tappable |
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 $length = null)
Assert that the prop is of the expected size. | from Has |
$this | has(string $key, null $value = null, Closure $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. | from Interaction |
mixed | prop(string $key = null)
Retrieve a prop within the current scope using "dot" notation. | |
AssertableJson | scope(string $key, Closure $callback)
Instantiate a new "scope" at the path of the given key. | |
Interaction | etc()
Disables the interaction check. | from Interaction |
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. | from Matching |
Matching | whereNot(string $key, mixed|Closure $expected)
Asserts that the property does not match the expected value. | from Matching |
Matching | whereAll(array $bindings)
Asserts that all properties match their expected values. | from Matching |
Matching | whereType(string $key, string|array $expected)
Asserts that the property is of the expected type. | from Matching |
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 |
Debugging | dump(string $prop = null)
Dumps the given props. | from Debugging |
void | dd(string $prop = null)
Dumps the given props and exits. | from Debugging |
void | interacted()
Asserts that all properties have been interacted with. | from Interaction |
static void | macro(string $name, object|callable $macro)
Register a custom macro. | from Macroable |
static void | mixin(object $mixin, bool $replace = true)
Mix another object into the class. | from Macroable |
static bool | hasMacro(string $name)
Checks if macro is registered. | from Macroable |
static void | flushMacros()
Flush the existing macros. | from Macroable |
static mixed | __callStatic(string $method, array $parameters)
Dynamically handle calls to the class. | from Macroable |
mixed | __call(string $method, array $parameters)
Dynamically handle calls to the class. | from Macroable |
$this|HigherOrderTapProxy | tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance. | from Tappable |
void | __construct(array $props, string $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. |
Details
Has count(string|int $key, int $length = null)
Assert that the prop is of the expected size.
abstract $this has(string $key, null $value = null, Closure $scope = null)
Ensure that the given prop exists.
Has hasAll(array|string $key)
Assert that all of the given props exist.
Has hasAny(array|string $key)
Assert that at least one of the given props exists.
Has missingAll(array|string $key)
Assert that none of the given props exist.
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 $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 $prop = null)
Dumps the given props.
void dd(string $prop = null)
Dumps the given props and exits.
void interacted()
Asserts that all properties have been interacted with.
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 $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.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/9.x/Illuminate/Testing/Fluent/AssertableJson.html