Download the PHP package ashc/laravel-json-asserter without Composer
On this page you can find all versions of the php package ashc/laravel-json-asserter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ashc/laravel-json-asserter
More information about ashc/laravel-json-asserter
Files in ashc/laravel-json-asserter
Package laravel-json-asserter
Short Description A trait for simplifying HTTP tests in Laravel
License MIT
Informations about the package laravel-json-asserter
laravel-json-asserter
A prototype tool to make writing and reading Laravel JSON assertions less painfull.
Example
Take the following JSON structure
Using the fluent JSON assertion system in Laravel to test the structure of the JSON we produce a test that looks like this:
Compared to the prototype assertion helper:
Usage
JsonAsserter uses an array to describe the structure and datatype of the JSON, and then uses the Laravel fluent JSON testing API behind the scenes to generate assertions.
It makes a JsonAsserter
trait available, just use the trait in your test files (or TestCase.php to automatically apply to all tests).
For JSON fields that are simple data-types, you can use string
, integer
, double
, boolean
and null
- the same as with Laravel's whereType()
and whereAllType()
methods.
In addition to the standard Laravel types, you can use a type of missing
to assert that the field is absent from the response.
For arrays and objects, you can use a nested array to describe the structure of the array/object.
For an object, the array must have a values subarray.
For an array, the array must have both values and count. Count representing the number of results expected in the array.
Nesting objects within arrays and vice versa is of course allowed.