Download the PHP package duxet/json_spec without Composer

On this page you can find all versions of the php package duxet/json_spec. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json_spec

Json Spec

Scrutinizer Code Quality Build Status

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.

If you working with JSON-based REST APIs there are several issues:

json_spec solves this problems as it normalize JSON before match it.

Let's see simple example:


{
   "id": 1421,
   "created_at": "1977-05-25 00:00:00"
   "last_name": "Skywalker",
   "first_name": "Luke",
}
        
      

{
   "first_name": "Luke",
   "last_name": "Skywalker"
}
        
      

json_spec will assume that this JSON documents are equal. Before asserting, json_spec will exclude keys id, created_at and updated_at from response JSON (List of excluded keys is configurable). Then it will normalize JSON (reorder keys, pretty-print) and after, just check for string equality. That's all. Also you can match JSON by given path instead of describing whole response in your specification, check is JSON collection contains some record and many more.

Installation

To install json_spec you may want to use composer:

After that you should enable json_spec behat extension and optionally add context provided with json_spec in your . For example:

Usage

json_spec provides you two ways of how you can use matchers:

Using json_spec Context

json_spec provides Behat context which implements steps utilizing all matchers provided by json_matcher. This is perfect for testing your app's JSON API.

One note. json_spec should have access to responses. If you are using Mink, that it's just fine. json_spec will get responses from Mink. This means that all you need to do to start working, is just to enable MinkExtension in your behat.yml:

That's all, now json_spec have access to all responses. You may also want to use behatch:rest context from sanpii/behatch-contexts instead of mink context.

If you are using your own context, which not using Mink, then just implement interface for your context:

Now, you can use the json_spec steps in your features:

The background steps above and the "visit" steps aren't provided by json_spec. The remaining steps, json_spec provides. They're versatile and can be used in plenty of different formats:

All instances of "should" above could be followed by "not" and all instances of "JSON" could be downcased and/or followed by "response."

Table Format

Another step exists that uses Behat's table formatting and wraps two of the above steps:

Then the JSON should have the following:

Any number of rows can be given. The step above is equivalent to:

If only one column is given:

This is equivalent to:

JSON Memory

There's one more Behat step that json_spec provides which hasn't been used above. It's used to memorize JSON for reuse in later steps. You can "keep" all or a portion of the JSON by giving a name by which to remember it.

You can memorize JSON at a path:

You can remember JSON at a path:

You can also remember JSON inline:

Also starting from version 0.2.3 you can inject memory helper into your feature context to define some variables. To do so, your context should implement MemoryHelperAware interface.

More Examples

Check out the features to see all the various ways you can use json_spec.

Using json matcher in your step definitions

To inject JsonMatcherFactory you can just implement JsonMatcherAware interface in your context, or just use JsonMatcherAwareTrait:

Contributing

If you come across any issues, please tell me . Pull requests (with tests) are appreciated. No pull request is too small. Please help with:

If you report a bug and don't include a fix, please include a failing test.

Credits


All versions of json_spec with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
fesor/json_matcher Version ~0.2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package duxet/json_spec contains the following files

Loading the files please wait ....