2017 © Pedro Peláez
 

behat-extension json-api-behat-extension

Rest Api Extension for Behat

image

rezzza/json-api-behat-extension

Rest Api Extension for Behat

  • Wednesday, November 29, 2017
  • by tyx
  • Repository
  • 8 Watchers
  • 27 Stars
  • 2,887 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 6 Open issues
  • 33 Versions
  • 0 % Grown

The README.md

RestApiExtension for Behat

Build Status, (*1)

Scrutinizer Code Quality, (*2)

For now only JSON api is supported to analyze response, but you could use REST part to perform request on any type of api., (*3)

Warning

From version 7.0, namespace vendor changed from Rezzza to Ubirak., (*4)

Install

Require the package as a development dependency :, (*5)

composer require --dev ubirak/rest-api-behat-extension

Don't forget to load the extension and the context if needed in your behat.yml :, (*6)

default:
    extensions:
        Ubirak\RestApiBehatExtension\Extension:
            rest:
                base_url: http://localhost:8888
                store_response: true
    suites:
        default:
            contexts:
                - Ubirak\RestApiBehatExtension\RestApiContext
                - Ubirak\RestApiBehatExtension\Json\JsonContext

Then you will need to require in your composer the http client you want to use, and the message factory., (*7)

Example:, (*8)

composer require --dev guzzlehttp/psr7 php-http/curl-client

Usage

You can use directly the JsonContext or RestApiContext by loading them in your behat.yml or use the RestApiBrowser and JsonInspector by adding them in the construct of your own context., (*9)

<?php
/**/

use Ubirak\RestApiBehatExtension\Rest\RestApiBrowser;
use Ubirak\RestApiBehatExtension\Json\JsonInspector;

class FeatureContext implements Context
{
    private $restApiBrowser;

    private $jsonInspector;

    public function __construct(RestApiBrowser $restApiBrowser, JsonInspector $jsonInspector)
    {
        $this->restApiBrowser = $restApiBrowser;
        $this->jsonInspector = $jsonInspector;
    }
}

The Versions