定制 genesis/mock-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

genesis/mock-api

Composer 安装命令:

composer require genesis/mock-api

包简介

Develop and run automated tests against a mock API.

README 文档

README

Have an application that depends on an API but is too much of a burden on testing? Replace your API with a mock API using this package and mock requests on the fly.

How to install

composer require genesis/mock-api
make -f ./vendor/genesis/mock-api/Makefile build
make mockapi-install

Start mock-api:

make mockapi-up

Test that the mock API is running:

curl http://0.0.0.0:8989/alive

Stop mock-api:

make mockapi-down

Find more commands in the generated Makefile.

Static mocks

You can add your static routes (ones that will be available as soon as you boot up the mock API) in the staticMocks folder. The data format is defined below and example request already exists.

Dynamic mocks

To mock a request POST your mocking request to /mocks with mockData json. Example mock request:

# POST /mocks
{
    "mockData": {
        "url": "/user/abc123",
        "get": [{
            "body": {
                "id": "abc123",
                "name": "Wahab Qureshi"
            }
        }]
     }
}

You can override a static mock with a dynamic one. Purging the mocks will revert the back to the static mock.

Full mock data options:

{
    "mockData": {
        "url": "/user/abc123",
        "get": [{
            "with": "/abc123/",
            "response_code": 301,
            "headers": {"lola": "123", "baby boo": "dudu"},
            "body": {
                "id": "abc123",
                "name": "Wahab Qureshi"
            },
            "proxy": {
                "url": "http://google.com",
                "headers": {
                    "app-token": "88374783847"
                }
            },
            "consecutive_responses": [{
                "response_code": 205,
                "body": {
                    "id": "abc123",
                    "name": "Wahab Qureshi"
                }
            }, {
                "response_code": 500,
                "body": "internal server error"
            }]
        }]
     }
}

mockData (object): Contains mock request information.

mockData.url (string): The URL to mock, can be an existing statically mocked URL.

mockData.<METHOD> ([]object): The method to mock for the URL.

mockData.<METHOD>.with (?string): A regex pattern to be applied to the URL optionally.

mockData.<METHOD>.response_code (?int): The response code to return optionally.

mockData.<METHOD>.headers (?object): The headers to return.

mockData.<METHOD>.body (mixed): The response content.

mockData.<METHOD>.consecutive_responses (?[]object): On consecutive calls return one after the other. Supports response_code, headers and body.

mockData.<METHOD>.proxy (?object): Proxy the response through another URL.

View mocked endpoints

View existing mock requests by visiting /mocks

Purge dynamic mocks

To purge all dynamic mocks created send GET request to /mocks?purge=true

Development:

Running tests is just a case of running the behat tests:

./vendor/bin/behat

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固