avto-dev/guzzle-url-mock 问题修复 & 功能扩展

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

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

avto-dev/guzzle-url-mock

最新稳定版本:v1.6.1

Composer 安装命令:

composer require avto-dev/guzzle-url-mock

包简介

URLs (fixed and regexps-based) mock handler for Guzzle 6/7

README 文档

README

logo

Guzzle URLs mock handler

Version Version Build Status Coverage Downloads count License

This package for easy mocking URLs (fixed and regexps-based) using Guzzle 6/Guzzle 7.

Install

Require this package with composer using the following command:

$ composer require avto-dev/guzzle-url-mock "^1.5"

Installed composer is required (how to install composer).

You need to fix the major version of package.

Usage

Create Guzzle client instance with passing handler instance, setup it, and make request:

<?php

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use AvtoDev\GuzzleUrlMock\UrlsMockHandler;

$handler = new UrlsMockHandler;
$client  = new Client([
    'handler' => HandlerStack::create($handler),
]);

$handler->onUriRequested('https://goo.gl', 'get', new Response(
    200, ['foo' => ['bar']], '<h1>All looks fine!</h1>'
));

$handler->onUriRegexpRequested('~https:\/\/goo\.gl\/.*~', 'post', new Response(
    404, [], 'Nothing found'
));

$client->request('get', 'https://goo.gl')->getBody()->getContents(); // '<h1>All looks fine!</h1>'
$client->request('post', 'https://goo.gl/foo', ['http_errors' => false])->getBody()->getContents(); // 'Nothing found'

Also you can use next handler methods:

Method name Description
getRequestsUriHistory() Get all requests URIs history
getLastRequestedUri() Get last requested URI
getLastRequest() Get last request instance
getLastOptions() Get last request options

Testing

For package testing we use phpunit framework and docker-ce + docker-compose as develop environment. So, just write into your terminal after repository cloning:

$ make build
$ make latest # or 'make lowest'
$ make test

Changes log

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

If you will find any package errors, please, make an issue in current repository.

License

This is open-sourced software licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-02