twentytwo-labs/behat-open-api

该软件包最新版本(1.0.5)没有可用的许可信息。

Behat 上下文

1.0.5 2024-05-30 19:14 UTC

This package is auto-updated.

Last update: 2024-08-30 19:52:08 UTC


README

Behat Open Api 上下文提供最常用的 Api Behat 测试。

安装

此扩展需要

  • Behat 3+
  • Mink 扩展

项目依赖

  1. 安装 Composer
  2. 使用 Composer 需求此软件包
$ composer require --dev twentytwo-labs/behat-open-api
  1. 通过在您的 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 :
          | ... |
      
    •   @Then the JSON should be match to:
          | ... |
      
      此步骤链接到 [Array-comparator](https://github.com/TwentytwoLabs/array-comparator 软件包)
  • 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