ubirak / rest-api-behat-extension
Behat 的 Rest Api 扩展
v8.3.0
2024-01-05 13:47 UTC
Requires
- php: >=7.2
- atoum/atoum: ^4
- behat/behat: ^3.8
- justinrainbow/json-schema: >=5.2.10 <6.0
- mtdowling/jmespath.php: ^2.3
- php-http/client-common: ^2.3
- php-http/discovery: ^1.13
- php-http/message: ^1.11
- psr/http-message: ^1.0
- symfony/config: ^4.4.12 | ~5.0 | ~6.0 | ~7.0
- symfony/dependency-injection: ^4.4.12 | ~5.0 | ~6.0 | ~7.0
- symfony/property-access: ^4.4.12 | ~5.0 | ~6.0 | ~7.0
- tolerance/tolerance: ^0.4.2
Requires (Dev)
- guzzlehttp/psr7: ^1.3
- php-http/guzzle7-adapter: ^0.1.1
- php-http/mock-client: ^1.0
- silex/silex: ~2.0
- symfony/process: ~4.0
Replaces
- rezzza/json-api-behat-extension: v8.3.0
- rezzza/rest-api-behat-extension: v8.3.0
This package is not auto-updated.
Last update: 2024-09-13 17:10:15 UTC
README
目前仅支持 JSON API 分析响应,但可以使用 REST 部分对任何类型的 API 进行请求。
警告
从版本 7.0
开始,命名空间供应商从 Rezzza
更改为 Ubirak
。
安装
将包作为开发依赖项要求
composer require --dev ubirak/rest-api-behat-extension
不要忘记在你的 behat.yml
中加载扩展和上下文(如果需要)
default: extensions: Ubirak\RestApiBehatExtension\Extension: rest: base_url: http://localhost:8888 store_response: true suites: default: contexts: - Ubirak\RestApiBehatExtension\RestApiContext - Ubirak\RestApiBehatExtension\Json\JsonContext
然后你需要在你的 composer 中要求你想要使用的 http 客户端和消息工厂。
示例
composer require --dev guzzlehttp/psr7 php-http/curl-client
用法
你可以直接使用 JsonContext
或 RestApiContext
,通过在 behat.yml 中加载它们,或者通过将它们添加到自己的上下文构造函数中,使用 RestApiBrowser
和 JsonInspector
。
<?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; } }