genesis/mock-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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

genesis/mock-api 适用场景与选型建议

genesis/mock-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 genesis/mock-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 genesis/mock-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 genesis/mock-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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