定制 mcustiel/phiremock-codeception-extension 二次开发

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

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

mcustiel/phiremock-codeception-extension

Composer 安装命令:

composer create-project mcustiel/phiremock-codeception-extension

包简介

Codeception extension for Phiremock. Allows to stub remote services for HTTP requests.

README 文档

README

Codeception extension to make working with Phiremock Server even easier. It allows to start a Phiremock Server before a suite is executed and stop it when the suite ends.

Latest Stable Version Build Status Scrutinizer Code Quality Monthly Downloads

Installation

Composer:

    "require-dev": {
        "mcustiel/phiremock-codeception-extension": "^3.0"
    }

Optionally, you can install Phiremock Server in case you want to have it between your dependencies. If not, you need to specify the path to phiremock in the configuration.

"require-dev": {
    "mcustiel/phiremock-codeception-extension": "^2.0",
    "mcustiel/phiremock-server": "^1.0",
    "guzzlehttp/guzzle": "^6.0"
}

Phiremock server has been made an optional dependency in case you want to run it from a phar file, a global composer dependency or in a docker container, and not have it as a project dependency.

Configuration

extensions:
    enabled:
        - \Codeception\Extension\Phiremock
    config:
        \Codeception\Extension\Phiremock:
            listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086 
            bin_path: ../vendor/bin # defaults to codeception_dir/../vendor/bin 
            logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir
            debug: true # defaults to false
            wait_until_ready: true # defaults to false
            wait_until_ready_timeout: 15 # (seconds) defaults to 30
            wait_until_ready_interval: 100 # (microseconds) defaults to 50000
            expectations_path: /my/expectations/path # defaults to tests/_expectations
            server_factory: \My\FactoryClass # defaults to 'default'
            extra_instances: [] # deaults to an empty array
            suites: [] # defaults to an empty array
            certificate: /path/to/cert # defaults to null
            certificate_key: /path/to/cert-key # defaults to null
            cert_passphrase: 'my-pass' # defaults to null

Note: Since Codeception version 2.2.7, extensions configuration can be added directly in the suite configuration file. That will avoid phiremock to be started for every suite.

Parameters

listen

Specifies the interface and port where phiremock must listen for requests.

Default: 0.0.0.0:8086

bin_path

Path where Phiremock Server's "binary" is located. You can, for instance, point to the location of the phar in your file system.

Default: codeception_dir/../vendor/bin/phiremock

logs_path

Path where to write the output.

Default: codeception's tests output dir

debug

Whether to write debug data to log file.

Default: false

start_delay

Time to wait after Phiremock Server is started before running the tests (used to give time to Phiremock Server to boot)

Default: 0

wait_until_ready

This is more robust alternative to start_delay. It will check if Phiremock Server is actually running before running the tests. Note: it depends on Phiremeock Client to be installed via composer (it is used to check the status of Phiremock Server).

Default: false

wait_until_ready_timeout

This will be used only if wait_until_ready is set to true. You can specify after how many seconds it will stop checking if Phiremock Server is running.

Default: 30

expectations_path

Specifies a directory to search for json files defining expectations to load by default.

Default: codecption_dir/_expectations

certificate

Path to a certificate file to allow phiremock-server to listen for secure https connections.

Default: null. Meaning phiremock will only listen on unsecured http connections.

certificate-key

Path to the certificate key file.

Default: null.

cert-passphrase

Path to the certificate passphrase used to encrypt the certificate (only needed if encrypted).

Default: null. Meaning no decryption based in passphrase will be performed.

suites

Specifies a list of suites for which the phiremock-server must be executed.

Default: [] Empty array, meaning that phiremock will be executed for each suite.

extra_instances

Allows to specify more instances of phiremock-server to run. This is useful if you want, for instance, run one instance listening for http and one listening for https connections. Each instance has its own configuration, and can separately run for different suites.

Default: [] Empty array, meaning that no extra phiremock-server instances are configured.

Example:

extensions:
    enabled:
        - \Codeception\Extension\Phiremock
    config:
        \Codeception\Extension\Phiremock:
            listen: 127.0.0.1:18080  
            debug: true 
            expectations_path: /my/expectations/path-1 
            suites: 
                - acceptance
            extra_instances: 
                - 
                    listen: 127.0.0.1:18081
                    debug: true
                    start_delay: 1
                    expectations_path: /my/expectations/path-2
                    suites:
                        - acceptance
                        - api
                    certificate: /path/to/cert
                    certificate_key: /path/to/cert-key 
                    cert_passphrase: 'my-pass' 

server_factory

Specifies a Factory class extending \Mcustiel\Phiremock\Server\Factory\Factory. Useful if you want to provide your own PSR. This works only if you install phiremock as a local dependency required in your composer file.

Default: default

Example: If this is in your composer.json:

"require-dev": {
    "mcustiel/phiremock-codeception-extension": "v2.0",
    "mcustiel/phiremock-server": "^1.0",
    "guzzlehttp/guzzle": "^7.0"

Then you can create a factory as follows:

<?php
namespace My\Namespace;

use GuzzleHttp;
use Mcustiel\Phiremock\Server\Factory\Factory;
use Psr\Http\Client\ClientInterface;

class FactoryWithGuzzle7 extends Factory
{
    public function createHttpClient(): ClientInterface
    {
        return new GuzzleHttp\Client();
    }
}

and in the extension config provide the fully qualified namespace to that class:

 enabled:
   - \Codeception\Extension\Phiremock
 config:
   \Codeception\Extension\Phiremock:
     server_factory: \My\Namespace\FactoryWithGuzzle7

See also:

mcustiel/phiremock-codeception-extension 适用场景与选型建议

mcustiel/phiremock-codeception-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.06M 次下载、GitHub Stars 达 31, 最近一次更新时间为 2016 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「http」 「mock」 「extension」 「server」 「codeception」 「tests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 mcustiel/phiremock-codeception-extension 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 31
  • Watchers: 5
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2016-03-04