class AssertableJsonString implements ArrayAccess, Countable

Properties

Jsonable|JsonSerializable|array|string $json

The original encoded json.

protected mixed $decoded

The decoded json contents.

Methods

__construct(Jsonable|JsonSerializable|array|string $jsonable)

Create a new assertable JSON string instance.

mixed
json(string|null $key = null)

Validate and return the decoded response JSON.

assertCount(int $count, string|null $key = null)

Assert that the response JSON has the expected count of items at the given key.

assertExact(array $data)

Assert that the response has the exact given JSON.

assertSimilar(array $data)

Assert that the response has the similar JSON as given.

assertFragment(array $data)

Assert that the response contains the given JSON fragment.

assertMissing(array $data, bool $exact = false)

Assert that the response does not contain the given JSON fragment.

assertMissingExact(array $data)

Assert that the response does not contain the exact JSON fragment.

assertMissingPath(string $path)

Assert that the response does not contain the given path.

bool
hasJsonPath(mixed $data, array $segments)

Determine whether a JSON path exists, where each wildcard matches any child at its level.

assertPath(string $path, mixed $expect)

Assert that the expected value and type exists at the given path in the response.

assertPathCanonicalizing(string $path, array $expect)

Assert that the given path in the response contains all of the expected values without looking at the order.

assertStructure(array|null $structure = null, array|null $responseData = null, bool $exact = false)

Assert that the response has a given JSON structure.

assertSubset(array $data, bool $strict = false)

Assert that the response is a superset of the given JSON.

array
reorderAssocKeys(array $data)

Reorder associative array keys to make it easy to compare arrays.

string
assertJsonMessage(array $data)

Get the assertion message for assertJson.

array
jsonSearchStrings(string|int $key, mixed $value)

Get the strings we need to search for when examining the JSON.

int
count()

Get the total number of items in the underlying JSON array.

bool
offsetExists(mixed $offset)

Determine whether an offset exists.

mixed
offsetGet(mixed $offset)

Get the value at the given offset.

void
offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

void
offsetUnset(mixed $offset)

Unset the value at the given offset.

Details

at line 37
__construct(Jsonable|JsonSerializable|array|string $jsonable)

Create a new assertable JSON string instance.

Parameters

Jsonable|JsonSerializable|array|string $jsonable

at line 59
mixed json(string|null $key = null)

Validate and return the decoded response JSON.

Parameters

string|null $key

Return Value

mixed

at line 67
AssertableJsonString assertCount(int $count, string|null $key = null)

Assert that the response JSON has the expected count of items at the given key.

Parameters

int $count
string|null $key

Return Value

AssertableJsonString

at line 91
AssertableJsonString assertExact(array $data)

Assert that the response has the exact given JSON.

Parameters

array $data

Return Value

AssertableJsonString

at line 108
AssertableJsonString assertSimilar(array $data)

Assert that the response has the similar JSON as given.

Parameters

array $data

Return Value

AssertableJsonString

at line 123
AssertableJsonString assertFragment(array $data)

Assert that the response contains the given JSON fragment.

Parameters

array $data

Return Value

AssertableJsonString

at line 148
AssertableJsonString assertMissing(array $data, bool $exact = false)

Assert that the response does not contain the given JSON fragment.

Parameters

array $data
bool $exact

Return Value

AssertableJsonString

at line 177
AssertableJsonString assertMissingExact(array $data)

Assert that the response does not contain the exact JSON fragment.

Parameters

array $data

Return Value

AssertableJsonString

at line 203
AssertableJsonString assertMissingPath(string $path)

Assert that the response does not contain the given path.

Parameters

string $path

Return Value

AssertableJsonString

at line 224
protected bool hasJsonPath(mixed $data, array $segments)

Determine whether a JSON path exists, where each wildcard matches any child at its level.

Parameters

mixed $data
array $segments

Return Value

bool

at line 252
AssertableJsonString assertPath(string $path, mixed $expect)

Assert that the expected value and type exists at the given path in the response.

Parameters

string $path
mixed $expect

Return Value

AssertableJsonString

at line 266
AssertableJsonString assertPathCanonicalizing(string $path, array $expect)

Assert that the given path in the response contains all of the expected values without looking at the order.

Parameters

string $path
array $expect

Return Value

AssertableJsonString

at line 276
AssertableJsonString assertStructure(array|null $structure = null, array|null $responseData = null, bool $exact = false)

Assert that the response has a given JSON structure.

Parameters

array|null $structure
array|null $responseData
bool $exact

Return Value

AssertableJsonString

at line 318
AssertableJsonString assertSubset(array $data, bool $strict = false)

Assert that the response is a superset of the given JSON.

Parameters

array $data
bool $strict

Return Value

AssertableJsonString

at line 333
protected array reorderAssocKeys(array $data)

Reorder associative array keys to make it easy to compare arrays.

Parameters

array $data

Return Value

array

at line 350
protected string assertJsonMessage(array $data)

Get the assertion message for assertJson.

Parameters

array $data

Return Value

string

at line 365
protected array jsonSearchStrings(string|int $key, mixed $value)

Get the strings we need to search for when examining the JSON.

Parameters

string|int $key
mixed $value

Return Value

array

at line 379
int count()

Get the total number of items in the underlying JSON array.

Return Value

int

at line 387
bool offsetExists(mixed $offset)

Determine whether an offset exists.

Parameters

mixed $offset

Return Value

bool

at line 395
mixed offsetGet(mixed $offset)

Get the value at the given offset.

Parameters

mixed $offset

Return Value

mixed

at line 403
void offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 411
void offsetUnset(mixed $offset)

Unset the value at the given offset.

Parameters

mixed $offset

Return Value

void