Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taluu/behapi
Behat extension for those who want to write acceptances tests for apis
https://github.com/taluu/behapi
api bdd behat behat-contexts behat-extension php php71 rest
Last synced: 2 months ago
JSON representation
Behat extension for those who want to write acceptances tests for apis
- Host: GitHub
- URL: https://github.com/taluu/behapi
- Owner: Taluu
- License: mit
- Created: 2016-06-17T09:18:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-22T13:18:18.000Z (about 2 years ago)
- Last Synced: 2024-10-12T12:22:22.762Z (2 months ago)
- Topics: api, bdd, behat, behat-contexts, behat-extension, php, php71, rest
- Language: PHP
- Homepage:
- Size: 401 KB
- Stars: 32
- Watchers: 5
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Behapi
======
Behat extension to help write describe features related to HTTP APIs.PHP 7.3, Behat 3.7 and a discoverable php-http client are required to make
this extension work.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`).You can find some examples on the `examples/` directory.
Howto
-----
Add this in your behat.yml (it's for the `default` configuration but you can
use it for any configurations actually) :```yaml
default:
suites:
main:
paths: ['%paths.base%/features']
services: '@Behapi\Container'
autowire: truecontexts:
#- 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.
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.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.Some services are provided to be injected in contexts, which are the following:
- `@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.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.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)A documentation will be made (soon hopefully) with more details.
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 !Thanks
------
This extension was made while I was working at
[@Wisembly](https://github.com/Wisembly), and heavily used for writing our
features and integration tests. Special thanks goes to
[@lunika](https://github.com/lunika), [@rgazelot](https://github.com/rgazelot)
and [@krichprollsch](https://github.com/krichprollsch), who helped conceived
this extension, and also pushed me to open-source it.Badges
------
[![Type Coverage](https://shepherd.dev/github/Taluu/Behapi/coverage.svg)](https://shepherd.dev/github/Taluu/Behapi)