PHPackages                             kielabokkie/jsonapi-behat-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. kielabokkie/jsonapi-behat-extension

ActiveBehat-extension[Testing &amp; Quality](/categories/testing)

kielabokkie/jsonapi-behat-extension
===================================

Behat extension for testing JSON APIs

v4.0.0(3y ago)1516.5k↓16.7%7[1 PRs](https://github.com/kielabokkie/jsonapi-behat-extension/pulls)MITPHPPHP ^8.0

Since Jul 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kielabokkie/jsonapi-behat-extension)[ Packagist](https://packagist.org/packages/kielabokkie/jsonapi-behat-extension)[ RSS](/packages/kielabokkie-jsonapi-behat-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (17)Used By (0)

JSON API Behat Extension
========================

[](#json-api-behat-extension)

[![Author](https://camo.githubusercontent.com/5660ca244b9dcf44b3d7795203c4cab7aaafa26dcc4499c8e347c1abd8b37942/687474703a2f2f696d672e736869656c64732e696f2f62616467652f666f6c6c6f772d406b69656c61626f6b6b69652d626c75652e7376673f6c6f676f3d74776974746572267374796c653d666c61742d737175617265)](https://twitter.com/kielabokkie)[![Packagist Version](https://camo.githubusercontent.com/0590a06d6d8a9352c88e2433ad119843ff4781af046738db0095bb2ca381d077/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b69656c61626f6b6b69652f6a736f6e6170692d62656861742d657874656e73696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kielabokkie/jsonapi-behat-extension)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

The JSON API Behat Extension provides step definitions for common testing scenarios specific to JSON APIs. It comes with easy ways to handle authentication through OAuth.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4

PHPPackage Version5.4v3.0.08.xv4.0+Installation
------------

[](#installation)

Recommended installation is by running the composer require command. This will install the latest stable version of this extension.

```
composer require kielabokkie/jsonapi-behat-extension --dev

```

Configuration
-------------

[](#configuration)

To use this extension you will have to add it under the `extensions` in your `behat.yml` file.

```
default:
    extensions:
        Kielabokkie\BehatJsonApi: ~

```

### Default parameters

[](#default-parameters)

Out of the box this extension has the following default parameters:

parametervaluebase\_urloauth\_uri/v1/oauth/tokenoauth\_client\_idtestclientoauth\_client\_secrettestsecretoauth\_use\_bearer\_tokenfalseoauth\_password\_grant\_requires\_client\_credentialsfalseYou can overwrite any of these parameters in the `behat.yml` file as needed.

```
default:
    extensions:
        Kielabokkie\BehatJsonApi:
            base_url: http://api.yourapp.dev
            parameters:
                oauth:
                    uri: /v1/oauth/token
                    client_id: myClientId
                    client_secret: myClientSecret
                    use_bearer_token: true
                    password_grant_requires_client_credentials: true

```

### Optional parameters

[](#optional-parameters)

To avoid having to use OAuth to retrieve an access token for each API call you can also specify an optional `access_token` in the parameters:

```
default:
    extensions:
        Kielabokkie\BehatJsonApi:
            parameters:
                access_token: 90dabed99acef998fd3e35280f2a0a3c30c00c8d

```

Usage
-----

[](#usage)

To use the step definitions provided by this extension just load the context class in your suites:

```
default:
  suites:
    default:
      contexts:
        - Kielabokkie\BehatJsonApi\Context\JsonApiContext
```

You will then have access to the following step definitions:

```
@Given I use the access token
@Given I use access token :token
@Given I oauth with :username and :password
@Given I oauth with :username and :password and scope :scope
@Given I oauth using the client credentials grant
@Given I oauth using the client credentials grant with scope :scope
@Given I oauth using the client credentials grant with :id and :secret
@Given I oauth using the client credentials grant with :id and :secret and scope :scope
@Given I add a :header header with the value :value
@Given I have the payload:
@When /^I request "(GET|PUT|PATCH|POST|DELETE) ([^"]*)"$/
@Then I get a :statuscode response
@Then scope into the :scope property
@Then scope into the first :scope element
@Then the structure matches:
@Then the :field property is an object
@Then the :field property is an array
@Then the :field property is an array with :count items
@Then the :field property is an empty array
@Then the :field property is an integer
@Then the :field property is a integer equaling/equalling :expected
@Then the :field property is a string
@Then the :field property is a string equaling/equalling :expected
@Then the :field property is a boolean
@Then the :field property is a boolean equaling/equalling :expected
@Then /^echo last request$/
@Then /^echo last response$

```

Note: The last two definitions are for debugging purposes and only show output when you use the `pretty` formatting option of Behat, i.e. `./vendor/bin/behat -f pretty`.

To get a list of all available step definitions including examples you can run the following command:

```
$ vendor/bin/behat -di

```

### Override the base url

[](#override-the-base-url)

In some cases you might want to override the base url for a specific suite. Below is an example of a `behat.yml` file. Here the custom url `http://hooks.yourapp.dev` is passed to the FeatureContext under the hooks suite.

```
default:
    autoload:
        - %paths.base%/tests/Behat/features/bootstrap
    suites:
        api:
            paths:
                - %paths.base%/tests/Behat/features/api
            contexts:
                - Kielabokkie\BehatJsonApi\Context\JsonApiContext: ~
        hooks:
            paths:
                - %paths.base%/tests/Behat/features/hooks
            contexts:
                - Kielabokkie\BehatJsonApi\Context\JsonApiContext:
                    - http://hooks.yourapp.dev
    extensions:
        Kielabokkie\BehatJsonApi: ~

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 84.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~212 days

Recently: every ~437 days

Total

13

Last Release

1413d ago

Major Versions

v1.0.4 → v2.0.02017-09-13

v2.0.3 → v3.0.02020-11-23

v3.0.0 → v4.0.02022-06-29

PHP version history (2 changes)v1.0.0-beta1PHP &gt;=5.4

v4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7824402e192649e35e5fa208e52a2bd8cab2afa343388b513f15a1bced95e600?d=identicon)[kielabokkie](/maintainers/kielabokkie)

---

Top Contributors

[![kielabokkie](https://avatars.githubusercontent.com/u/1221750?v=4)](https://github.com/kielabokkie "kielabokkie (53 commits)")[![ABGEO](https://avatars.githubusercontent.com/u/19558543?v=4)](https://github.com/ABGEO "ABGEO (3 commits)")[![damian-nz](https://avatars.githubusercontent.com/u/7383198?v=4)](https://github.com/damian-nz "damian-nz (3 commits)")[![ademarco](https://avatars.githubusercontent.com/u/153362?v=4)](https://github.com/ademarco "ademarco (2 commits)")[![bircher](https://avatars.githubusercontent.com/u/2198600?v=4)](https://github.com/bircher "bircher (1 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (1 commits)")

---

Tags

behatbehat-extensionjson-apisoauthtestingjsonapitestrestContextBehat

### Embed Badge

![Health badge](/badges/kielabokkie-jsonapi-behat-extension/health.svg)

```
[![Health](https://phpackages.com/badges/kielabokkie-jsonapi-behat-extension/health.svg)](https://phpackages.com/packages/kielabokkie-jsonapi-behat-extension)
```

###  Alternatives

[ubirak/rest-api-behat-extension

Rest Api Extension for Behat

41327.0k2](/packages/ubirak-rest-api-behat-extension)[imbo/behat-api-extension

API extension for Behat

1082.5M9](/packages/imbo-behat-api-extension)[teaandcode/behat-guzzle-extension

Behat API extension using Guzzle Service Descriptions to functionally test API endpoints

1017.7k](/packages/teaandcode-behat-guzzle-extension)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
