Download the PHP package estahn/phpunit-json-assertions without Composer
On this page you can find all versions of the php package estahn/phpunit-json-assertions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download estahn/phpunit-json-assertions
More information about estahn/phpunit-json-assertions
Files in estahn/phpunit-json-assertions
Package phpunit-json-assertions
Short Description JSON assertions for PHPUnit (including JSON Schema)
License MIT
Homepage https://github.com/estahn/phpunit-json-assertions
Informations about the package phpunit-json-assertions
phpunit-json-assertions
JSON assertions for PHPUnit includes traits/methods to help validate your JSON data through various methods.
Features
- Validate your JSON data via JSON Schema
- describes your existing data format
- clear, human- and machine-readable documentation
- complete structural validation, useful for
- automated testing
- validating client-submitted data
- See more details here
- Access JSON data through expressions (e.g.
foo.bar[3]
)- See more details here
Install
$ composer require estahn/phpunit-json-assertions --dev
or in your composer.json
:
Asserts
Assert | Description | Available in |
---|---|---|
assertJsonMatchesSchema | Asserts that json content is valid according to the provided schema file | All |
assertJsonMatchesSchemaString | Asserts that json content is valid according to the provided schema string | All |
assertJsonValueEquals | Asserts if the value retrieved with the expression equals the expected value | All |
assertJsonValueEquals | Asserts if the value retrieved with the expression equals the expected value | All |
assertJsonResponse | Asserts that a response is successful and of type json | Symfony |
Usage
You can either use the trait
or class
version.
Trait
Class
In case you don't want to use the trait
you can use the provided class wich extends from \PHPUnit_Framework_TestCase
.
You can either extend your test case or use the static methods like below.
Schema storage
The schema storage of justinrainbow/json-schema
allows to register schemas which will effectively override the actual schema location.
Example:
The resolver will fetch the schema from this endpoint and match the JSON document against it. Using schema storage you're able to override this behaviour.
With this in place the resolver will take the schema that is already in place without downloading it again.
Extensions
phpunit-json-assertions
provides extensions for simpler handling in different use cases.
Symfony HttpFoundation Component
The extension EnricoStahn\JsonAssert\Extension\Symfony
allows to pass in the actual response object generated
by the symfony framework and takes care of the decoding part.
BEFORE:
AFTER:
Tests
To run the test suite, you need composer.
$ composer install
$ bin/phpunit
Badge Mania
Alternatives
- https://github.com/martin-helmich/phpunit-json-assert - Doesn't support JSON Schema and uses JSONPath instead of jmespath.php
License
The phpunit-json-assertions library is licensed under the MIT.
Stargazers over time
All versions of phpunit-json-assertions with dependencies
justinrainbow/json-schema Version ^5.0
mtdowling/jmespath.php Version ^2.3
ext-json Version *