2017 © Pedro Peláez
 

library behapi

Test your remote api locally through Behat

image

taluu/behapi

Test your remote api locally through Behat

  • Thursday, April 12, 2018
  • by Talus
  • Repository
  • 3 Watchers
  • 18 Stars
  • 4,735 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 26 Versions
  • 8 % Grown

The README.md

Behapi

Behat extension to help write describe features related to HTTP APIs., (*1)

PHP 7.3, Behat 3.7 and a discoverable php-http client are required to make this extension work., (*2)

Installing this extension requires you to require taluu/behapi and an implementation of a http client (providing psr/http-client-implementation ^1.0, psr/http-factory-implementation ^1.0 and psr/http-message-implementation ^1.0)., (*3)

You can find some examples on the examples/ directory., (*4)

Howto

Add this in your behat.yml (it's for the default configuration but you can use it for any configurations actually) :, (*5)

default:
  suites:
    main:
      paths: ['%paths.base%/features']
      services: '@Behapi\Container'
      autowire: true

      contexts:
        #- List
        #- your
        #- contexts
        #- here

        # examples :
        - Behapi\Http\RequestContext: ~
        - Behapi\Http\ResponseContext: ~

  extensions:
    Behapi\Behapi:
      base_url: 'http://localhost'

The base_url is the only requirement in the config for this extension to work., (*6)

There are other configurations keys, such as which formatter to use in a debug environment, which headers you want to output in request or response while debugging ; Use the --config-reference flag when invoking behat to have more information on the available configuration., (*7)

After having installed the extension, you can then use the provided contexts such as the Behapi\Http\RequestContext for the http api operations. In order to use them, you need to use behapi's container (@Behapi\Container), or a container capable of using behapi's container., (*8)

Some services are provided to be injected in contexts, which are the following:, (*9)

  • @Http\Client\Common\PluginClientBuilder, which will build a Http\Client\Common\PluginClient when needed
  • @Behapi\HttpHistory\History, which is a sort of a container with the last requests done and last responses received
  • @Http\Message\MessageFactory
  • @Http\Message\StreamFactory

Note: You don't really need to bother with the services names, as they are compatible with behat's auto-wiring feature., (*10)

In order to enable the Json assertions, you need to use the Behapi\Context\Json context. Note that if you use the json context, you should have used the client provided by the client builder used in the Behapi\Http\RequestContext context., (*11)

If you need to play with the request being built, or the response created when the request is sent, you need to inject the @Behapi\HttpHistory\History. It is automatically reseted between scenarios (and scenarios outlines), (*12)

A documentation will be made (soon hopefully) with more details., (*13)

Contributing

Contributing (issues, pull-requests) are of course always welcome ! Be sure to respect the standards (such as psr-2, ... etc), follow proper git etiquette (atomic commits, ...), proper conduct too and it should be fine !, (*14)

Thanks

This extension was made while I was working at @Wisembly, and heavily used for writing our features and integration tests. Special thanks goes to @lunika, @rgazelot and @krichprollsch, who helped conceived this extension, and also pushed me to open-source it., (*15)

Badges

Type Coverage, (*16)

The Versions

12/04 2018

dev-master

9999999-dev

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

12/04 2018

v0.10.0

0.10.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

11/04 2018

dev-moar-debug-tweaks

dev-moar-debug-tweaks

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

11/04 2018

dev-tuple-history

dev-tuple-history

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

11/04 2018

0.9.x-dev

0.9.9999999.9999999-dev

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

11/04 2018

v0.9.1

0.9.1.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

23/02 2018

v0.9.0

0.9.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

19/02 2018

v0.8.2

0.8.2.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

16/02 2018

v0.8.1

0.8.1.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

16/02 2018

v0.8.0

0.8.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

15/02 2018

v0.7.0

0.7.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

09/02 2018

v0.6.1

0.6.1.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

09/02 2018

v0.6.0

0.6.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

02/02 2018

dev-remove-twig

dev-remove-twig

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

25/09 2017

v0.5.3

0.5.3.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

24/09 2017

v0.5.2

0.5.2.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

24/09 2017

v0.5.1

0.5.1.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

18/09 2017

v0.5.0

0.5.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

17/09 2017

v0.4.0

0.4.0.0

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

17/09 2017

dev-php-matcher

dev-php-matcher

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

31/03 2017

dev-implementations-details

dev-implementations-details

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts

31/03 2017

dev-move-tree

dev-move-tree

Test your remote api locally through Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

api extension behat contexts