baopham/api-mocker 问题修复 & 功能扩展

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

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

baopham/api-mocker

Composer 安装命令:

composer require baopham/api-mocker

包简介

API mocker for Laravel apps

README 文档

README

Laravel package to mock API endpoints.

If your apps need to integrate with other APIs (Github, Marketo, etc.), you don't want to invoke their API calls during testing. With this package, you can quickly mock the endpoints and it can be especially useful for Behat tests.

Usage:

  1. composer require baopham/api-mocker --dev

  2. Register Service Provider in app/Providers/AppServiceProvider.php:

public function register()
{
    if ($this->app->environment() == 'testing') {
        $this->app->register('BaoPham\ApiMocker\ApiMockerServiceProvider');
    }
}
  1. php artisan vendor:publish

  2. Update the new config file: config/apimocker.php:

<?php

return [
    /*
    |--------------------------------------------------------------------------------------------------
    | Mock on/off
    |--------------------------------------------------------------------------------------------------
    |
    | Determine if the endpoints below should be mocked.
    |
    */

    'should_mock' => env('API_MOCKER_ON', false),

    /*
    |--------------------------------------------------------------------------------------------------
    | Endpoints
    |--------------------------------------------------------------------------------------------------
    |
    | Array of endpoints to be mocked, keyed by the route's path.
    |
    | - fixture: path to the fixture file for the response content, could be JSON or XML.
    |
    | - middleware: an array of middlewares to be applied for this endpoint.
    |
    | - methods: GET, POST, PUT, DELETE. If not defined, it will not check against the method.
    |
    | - code: the response code should be returned. Default to 200.
    |
    | - placeholder: boolean (false by default). Set to `true` if you want to replace the
    |   placeholders in your fixture with the request parameters.
    |
    |     e.g. In your fixture: { "status": "ok", "description": "Folder {{name}} has been updated" }
    |
    |          Request: POST api/v1/folders/123?placeholder_name=BP (prefix with `placeholder_`)
    |
    |          Response will be: { "status": "ok", "description": "Folder BP has been updated" }
    |
    |   This is useful for Behat test for example, when you want to ensure you see the right status message.
    |
    |
    */

    'endpoints' => [

        'api/v1/folders/{id}' => [
            'fixture' => '/path/to/fixture.json',
            'middleware' => ['auth'],
            'methods' => ['POST'],
            'code' => 200,
            'placeholder' => true,
        ],
    ]

];

Requirements:

Laravel 5.1

TODOs:

  • Tests

License:

MIT

Author:

Bao Pham

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固