承接 kagency/http-replay 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kagency/http-replay

Composer 安装命令:

composer require kagency/http-replay

包简介

Library to replay and compare HTTP requets and responses

README 文档

README

Travis Build Status

This is a libaray to replay requests and responses in tests. It allows to filter the responses to remove values, one does not want to assert on.

Supported Tools

Supported recordings (Reader):

Supported frameworks (MessageHandler):

Workflow

The workflow for using this test helper could be:

First record some HTTP interaction using MitmDump, executing something like this:

mitmdump -P http://my-website:80/ -p 8080 --anticache -z -w recordFile.tns

The stored file can then be replayed against your application – in my case a Symfony2 stack – by implementing an integration test like this:

$messageHandler = new MessageHandler\Symfony2();
$filter = new ResponseFilter\Dispatcher(array(
    new ResponseFilter\Json(),
    new ResponseFilter\Headers(array(
        'date',
        'etag',
    )),
));

$reader = new Reader\MitmDump($messageHandler);
$interactions = $reader->readInteractions('recordFile.tns');

foreach ($interactions as $interaction) {
    $actualResponse = $app->runRequest($interaction->request);

    $this->assertEquals(
        $filter->filterResponse($messageHandler->simplifyResponse($interaction->request, $interaction->response)),
        $filter->filterResponse($messageHandler->simplifyResponse($interaction->request, $actualResponse))
    );
}

This example only implements a very basic set of response filters. You can implement conditional response filters, which only act for certain request URLs and filter, for example, certain JSON properties out of the response.

This example assumes $app is some Symfony2 app, where the method runRequest() recieves a Request object and returns a Response object.

Response Filters

A list of currently implemented response filters

Dispatcher

Takes an array of response filters to apply to the responses. You usually want to use this one to be able to easily apply a set of filters.

Json

Tries to parse JSON to make it easier to compare in tests. Also makes other response filters possible, like the JsonFilter filter.

Takes no arguments.

JsonFilter

Filters out a defined set of properties from a JSON response. Especially sensible, if your JSON response contains fields like dates or revisions.

Receives a list of properties to remove as a constructor argument.

Headers

Implements a blacklist for HTTP headers. Removes those headers from the response. This is especially useful to remove Date and Etag headers, for example.

Receives a list of headers to remove as a constructor argument.

MultipartMixed

Replaces the random boundary string in multipart/mixed responses, to make it possible to comapre them.

Takes no arguments.

ConditionalPathRegexp

Takes to arguments:

  • Regular expression to match the requested path
  • Aggregate filter

Only applies the aggregate filter, if the regular expression matches the requested path.

Verify the Build

You can verify the build by running ant:

ant

This installs all required tools using composer and then runs the tests and static source code verification. You might also run all the tools manually, like:

vendor/bin/phpunit

kagency/http-replay 适用场景与选型建议

kagency/http-replay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 kagency/http-replay 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-19