├── .editorconfig ├── .gitignore ├── .php_cs ├── .travis.yml ├── README.md ├── behat.yml ├── composer.json ├── composer.lock ├── features ├── bootstrap │ └── FeatureContext.php ├── common.feature ├── equivalence.feature ├── files.feature ├── inclusion.feature ├── memory.feature ├── paths.feature ├── sizes.feature └── types.feature ├── phpspec.yml ├── spec ├── JsonSpec │ ├── Behat │ │ └── Helper │ │ │ └── MemoryHelperSpec.php │ └── JsonLoaderSpec.php └── support │ └── files │ ├── one.json │ ├── project │ ├── one.json │ ├── two.json │ └── version │ │ ├── one.json │ │ └── two.json │ └── two.json └── src ├── Behat ├── Context │ ├── ArgumentResolver │ │ └── DependencyResolver.php │ ├── ContextResolver │ │ └── JsonSpecContextResolver.php │ ├── Initializer │ │ ├── JsonHolderAwareInitializer.php │ │ ├── JsonMatcherAwareInitializer.php │ │ └── MemoryHelperAwareInitializer.php │ ├── JsonHolderAware.php │ ├── JsonMatcherAware.php │ ├── JsonSpecContext.php │ ├── MemoryHelperAware.php │ └── Traits │ │ └── JsonMatcherAwareTrait.php ├── Extension.php ├── Helper │ └── MemoryHelper.php ├── JsonProvider │ ├── JsonHolder.php │ └── MinkJsonProvider.php └── Resources │ └── services │ ├── mink_integration.yml │ └── services.yml ├── Exception ├── JsonSpecException.php ├── MissingDirectoryException.php └── MissingFileException.php └── JsonLoader.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [**.feature] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [**.php] 17 | indent_style = space 18 | indent_size = 4 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /bin 3 | /vendor -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in(__DIR__.'/src') 5 | ; 6 | 7 | return Symfony\CS\Config\Config::create() 8 | ->finder($finder) 9 | ; 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | matrix: 10 | allow_failures: 11 | - php: hhvm 12 | 13 | before_script: 14 | - composer install 15 | 16 | script: 17 | - bin/phpspec run 18 | - bin/behat 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Json Spec 2 | =================== 3 | 4 | [](https://scrutinizer-ci.com/g/fesor/json_spec/?branch=master) [](https://travis-ci.org/fesor/json_spec) 5 | 6 | Json Spec provides set of easy-to-use matcher that should help you to validate data in JSON responses from your api with less pain. 7 | 8 | If you working with JSON-based REST APIs there are several issues: 9 | 10 | - You can't simply check is a response is equal to given string as there are things like server-generated IDs or keys sorting. 11 | - Key ordering should be the same both for your API and for expected JSON. 12 | - Matching the whole responses breaks DRY for the spec 13 | 14 | `json_spec` solves this problems as it normalize JSON before match it. 15 | 16 | Let's see simple example: 17 | 18 |
21 |
22 |
31 | |
32 |
33 |
34 |
41 | |
42 |