<commit_before># phpunit-json-assertions

[![Latest Stable Version](https://poser.pugx.org/estahn/phpunit-json-assertions/version.png)](https://packagist.org/packages/estahn/phpunit-json-assertions)
[![Total Downloads](https://poser.pugx.org/estahn/phpunit-json-assertions/d/total.png)](https://packagist.org/packages/estahn/phpunit-json-assertions)
[![Dependency Status](https://www.versioneye.com/user/projects/56e8f6404e714c0035e760f3/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56e8f6404e714c0035e760f3)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/581c093b-833a-49c2-a05c-d99aaf8f39c2/mini.png)](https://insight.sensiolabs.com/projects/581c093b-833a-49c2-a05c-d99aaf8f39c2)
[![Build Status](https://travis-ci.org/estahn/phpunit-json-assertions.png?branch=master)](https://travis-ci.org/estahn/phpunit-json-assertions)
[![StyleCI](https://styleci.io/repos/53177096/shield)](https://styleci.io/repos/53177096)

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](http://json-schema.org/)
* Access JSON data through expressions (e.g. `foo.bar[3]`)
    * See more details [here](http://jmespath.org/examples.html)

## Install

    $ composer require estahn/phpunit-json-assertions --dev
    
or in your `composer.json`:

```json
{
    "require-dev": {
        "estahn/phpunit-json-assertions": "@stable"
    }
}
```

## 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

```php
<?php

namespace EnricoStahn\JsonAssert\Tests;

use EnricoStahn\JsonAssert\Assert as JsonAssert;

class MyTestCase extends \PHPUnit_Framework_TestCase
{
    use JsonAssert;<commit_msg>Add link to wiki page for assertJsonMatchesSchema<commit_after># phpunit-json-assertions

[![Latest Stable Version](https://poser.pugx.org/estahn/phpunit-json-assertions/version.png)](https://packagist.org/packages/estahn/phpunit-json-assertions)
[![Total Downloads](https://poser.pugx.org/estahn/phpunit-json-assertions/d/total.png)](https://packagist.org/packages/estahn/phpunit-json-assertions)
[![Dependency Status](https://www.versioneye.com/user/projects/56e8f6404e714c0035e760f3/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56e8f6404e714c0035e760f3)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/581c093b-833a-49c2-a05c-d99aaf8f39c2/mini.png)](https://insight.sensiolabs.com/projects/581c093b-833a-49c2-a05c-d99aaf8f39c2)
[![Build Status](https://travis-ci.org/estahn/phpunit-json-assertions.png?branch=master)](https://travis-ci.org/estahn/phpunit-json-assertions)
[![StyleCI](https://styleci.io/repos/53177096/shield)](https://styleci.io/repos/53177096)

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](http://json-schema.org/)
* Access JSON data through expressions (e.g. `foo.bar[3]`)
    * See more details [here](http://jmespath.org/examples.html)

## Install

    $ composer require estahn/phpunit-json-assertions --dev
    
or in your `composer.json`:

```json
{
    "require-dev": {
        "estahn/phpunit-json-assertions": "@stable"
    }
}
```

## Asserts

| Assert                        | Description                                                                  | Available in |
| ----------------------------- | ---------------------------------------------------------------------------- | ------------ |
| [assertJsonMatchesSchema](https://github.com/estahn/phpunit-json-assertions/wiki/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

```php
<?php

namespace EnricoStahn\JsonAssert\Tests;

use EnricoStahn\JsonAssert\Assert as JsonAssert;

class MyTestCase extends \PHPUnit_Framework_TestCase
{
    use JsonAssert;
{'fraction_non_alphanumeric': 0.15221914008321774, 'fraction_numerical': 0.032246879334257975, 'mean_word_length': 3.0914893617021275, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 25, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '998651', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1678, 'n_words': 369}