kielabokkie/jsonapi-behat-extension
Composer 安装命令:
composer require kielabokkie/jsonapi-behat-extension
包简介
Behat extension for testing JSON APIs
README 文档
README
The JSON API Behat Extension provides step definitions for common testing scenarios specific to JSON APIs. It comes with easy ways to handle authentication through OAuth.
Requirements
- PHP >= 5.4
| PHP | Package Version |
|---|---|
| 5.4 | v3.0.0 |
| 8.x | v4.0+ |
Installation
Recommended installation is by running the composer require command. This will install the latest stable version of this extension.
composer require kielabokkie/jsonapi-behat-extension --dev
Configuration
To use this extension you will have to add it under the extensions in your behat.yml file.
default:
extensions:
Kielabokkie\BehatJsonApi: ~
Default parameters
Out of the box this extension has the following default parameters:
| parameter | value |
|---|---|
| base_url | http://localhost:8000 |
| oauth_uri | /v1/oauth/token |
| oauth_client_id | testclient |
| oauth_client_secret | testsecret |
| oauth_use_bearer_token | false |
| oauth_password_grant_requires_client_credentials | false |
You can overwrite any of these parameters in the behat.yml file as needed.
default:
extensions:
Kielabokkie\BehatJsonApi:
base_url: http://api.yourapp.dev
parameters:
oauth:
uri: /v1/oauth/token
client_id: myClientId
client_secret: myClientSecret
use_bearer_token: true
password_grant_requires_client_credentials: true
Optional parameters
To avoid having to use OAuth to retrieve an access token for each API call you can also specify an optional access_token in the parameters:
default:
extensions:
Kielabokkie\BehatJsonApi:
parameters:
access_token: 90dabed99acef998fd3e35280f2a0a3c30c00c8d
Usage
To use the step definitions provided by this extension just load the context class in your suites:
default: suites: default: contexts: - Kielabokkie\BehatJsonApi\Context\JsonApiContext
You will then have access to the following step definitions:
@Given I use the access token
@Given I use access token :token
@Given I oauth with :username and :password
@Given I oauth with :username and :password and scope :scope
@Given I oauth using the client credentials grant
@Given I oauth using the client credentials grant with scope :scope
@Given I oauth using the client credentials grant with :id and :secret
@Given I oauth using the client credentials grant with :id and :secret and scope :scope
@Given I add a :header header with the value :value
@Given I have the payload:
@When /^I request "(GET|PUT|PATCH|POST|DELETE) ([^"]*)"$/
@Then I get a :statuscode response
@Then scope into the :scope property
@Then scope into the first :scope element
@Then the structure matches:
@Then the :field property is an object
@Then the :field property is an array
@Then the :field property is an array with :count items
@Then the :field property is an empty array
@Then the :field property is an integer
@Then the :field property is a integer equaling/equalling :expected
@Then the :field property is a string
@Then the :field property is a string equaling/equalling :expected
@Then the :field property is a boolean
@Then the :field property is a boolean equaling/equalling :expected
@Then /^echo last request$/
@Then /^echo last response$
Note: The last two definitions are for debugging purposes and only show output when you use the pretty formatting option of Behat, i.e. ./vendor/bin/behat -f pretty.
To get a list of all available step definitions including examples you can run the following command:
$ vendor/bin/behat -di
Override the base url
In some cases you might want to override the base url for a specific suite. Below is an example of a behat.yml file. Here the custom url http://hooks.yourapp.dev is passed to the FeatureContext under the hooks suite.
default:
autoload:
- %paths.base%/tests/Behat/features/bootstrap
suites:
api:
paths:
- %paths.base%/tests/Behat/features/api
contexts:
- Kielabokkie\BehatJsonApi\Context\JsonApiContext: ~
hooks:
paths:
- %paths.base%/tests/Behat/features/hooks
contexts:
- Kielabokkie\BehatJsonApi\Context\JsonApiContext:
- http://hooks.yourapp.dev
extensions:
Kielabokkie\BehatJsonApi: ~
kielabokkie/jsonapi-behat-extension 适用场景与选型建议
kielabokkie/jsonapi-behat-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.64k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2015 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「rest」 「api」 「Behat」 「test」 「Context」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kielabokkie/jsonapi-behat-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kielabokkie/jsonapi-behat-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kielabokkie/jsonapi-behat-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 16.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-07