twentytwo-labs / behat-open-api
该软件包最新版本(1.0.5)没有可用的许可信息。
Behat 上下文
1.0.5
2024-05-30 19:14 UTC
Requires
- php: >=8.1
- ext-json: *
- ext-mbstring: *
- behat/behat: ^3.0
- friends-of-behat/mink-extension: ^2.6
- guzzlehttp/psr7: ^2.3
- symfony/http-foundation: ^5.0|^6.0|^7.0
- symfony/property-access: ^5.0|^6.0|^7.0
- symfony/serializer: ^5.0|^6.0|^7.0
- twentytwo-labs/api-validator: ^2.0
- twentytwo-labs/array-comparator: ^1.0
- webmozart/assert: ^1.11
Requires (Dev)
- friends-of-behat/mink-browserkit-driver: ^1.6
- friendsofphp/php-cs-fixer: ^3.8
- infection/infection: ^0.28
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^10.4
- squizlabs/php_codesniffer: ^3.6
README
Behat Open Api 上下文提供最常用的 Api Behat 测试。
安装
此扩展需要
- Behat 3+
- Mink 扩展
项目依赖
- 安装 Composer
- 使用 Composer 需求此软件包
$ composer require --dev twentytwo-labs/behat-open-api
- 通过在您的
behat.yml
中指定其类来激活扩展
# behat.yml default: # ... extensions: TwentytwoLabs\BehatOpenApiExtension: schemaFile: "file:///path/to/your/schema" #optinal
使用方法
在 behat.yml
中,启用所需上下文
default: suites: default: contexts: - TwentytwoLabs\BehatOpenApiExtension\Context\DebugContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\RestContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\JsonContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\OpenApiContext: ~
示例
-
TwentytwoLabs\BehatOpenApiExtension\Context\DebugContext
@Then 打印最后响应头
@Then 打印分析器链接
-
TwentytwoLabs\BehatOpenApiExtension\Context\JsonContext
@Then 响应应在 JSON 中
@Then 响应不应在 JSON 中
@Then JSON 节点 :node 应等于 :text
@Then JSON 节点应等于
@Then JSON 节点 :node 应匹配 :pattern
@Then JSON 节点 :node 应为 null
@Then JSON 节点 :node 不应为 null
@Then JSON 节点 :node 应为 true
@Then JSON 节点 :node 应为 false
@Then JSON 节点 :node 应等于字符串 :text
@Then JSON 节点 :node 应等于数字 :number
@Then JSON 节点 :node 应有 :count 个元素
@Then JSON 节点 :node 应包含 :text
@Then JSON 节点 :node 不应包含 :text
-
@Then the JSON nodes should contain: | ... |
-
@Then the JSON nodes should not contain: | ... |
@Then JSON 节点 :name 应存在
@Then JSON 节点 :name 应不存在
@Then JSON 应等于
-
@Then I should see JSON with key : | ... |
-
此步骤链接到 [Array-comparator](https://github.com/TwentytwoLabs/array-comparator 软件包)@Then the JSON should be match to: | ... |
-
TwentytwoLabs\BehatOpenApiExtension\Context\OpenApiContext
@Then 响应应根据操作 id :operationId 有效
-
TwentytwoLabs\BehatOpenApiExtension\Context\RestContext
@Then 我添加了 :name 标头等于 :value
@Given 我向 :path 发送了 :method 请求
-
@Given I send a :method request to :path with parameters: | key | value | | ... | ..... |
-
@Given I send a :method request to :path with body: """ { #... } """
@Then 响应状态码应等于 (?P<code>\d+)$/
-
@Then the response should be equal to: """ { # ... } """
@Then 响应应为空
@Then 标头 :name 应等于 :value
@Then 标头 :name 不应等于 :value
@Then 标头 :name 应包含 :value
@Then 标头 :name 不应包含 :value
@Then 标头 :name 应不存在
@Then 标头 :name 应匹配 :regex
@Then 标头 :name 不应匹配 :regex
@Then 响应应在将来过期
@Then 响应应编码为 :encoding