phiremock/phiremock-codeception-extension
Composer 安装命令:
composer create-project phiremock/phiremock-codeception-extension
包简介
Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.
README 文档
README
Codeception extension and module to make working with Phiremock even easier. It allows to start a Phiremock server specifically for the acceptance tests to run or to connect to an already running Phiremock server.
Installation
Composer:
This project is published in packagist, so you just need to add it as a dependency in your composer.json:
"require-dev": { "mcustiel/phiremock-codeception-extension": "*" }, "minimum-stability": "dev"
NOTE Phiremock uses a dev-master version of react/http to work. Because of this, until reactphp guys tag a new version you will need to set your project's minimum stability to dev.
How to use
Extension
The extension provides an easy way to start a Phiremock server with configured host, port, debug mode and logs path.
Configuration
In codeception.yml you will need to enable Phiremock extension and configure it in a proper way:
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 startDelay: 1 # default to 0 expectations_path: /my/expectations/path
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.
Phiremock uses annotations internally. To be able to run the extension, the annotations autoloader must be activated. To do this, you must add the next lines in the bootstrap file where you include your composer autoloader:
$loader = require APP_ROOT . '/vendor/autoload.php'; \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);
Parameters
- listen: Specifies the interface and port where phiremock must listen for requests
- bin_path: Path where Phiremock "binary" is located
- logs_path: Path where to write the output
- debug: Where to write debug data to log files
- startDelay: Time to wait after Phiremock was started to start running the tests (used to give time to Phiremock to boot)
- expectations_path: Specifies a directory to search for json files defining expectations to load by default.
Module
The module allows you to connect to a Phiremock server and to interact with it in a semantic way through the codeception actor in your tests.
Configuration
You need to enable Phiremock module in your suite's configuration file:
modules: enabled: - Phiremock: host: 127.0.0.1 port: 18080 resetBeforeEachTest: false # if set to true, executes `$I->haveACleanSetupInRemoteService` before each test.
Use
The module provides the following handy methods to communicate with Phiremock server:
expectARequestToRemoteServiceWithAResponse
Allows you to setup an expectation in Phiremock, specifying the expected request and the response the server should give for it:
$I->expectARequestToRemoteServiceWithAResponse( Phiremock::on( A::getRequest()->andUrl(Is::equalTo('/some/url')) )->then( Respond::withStatusCode(203)->andBody('I am a response') ) );
haveACleanSetupInRemoteService
Cleans the server of all configured expectations, scenarios and requests history, and reloads expectation files.
$I->haveACleanSetupInRemoteService();
dontExpectRequestsInRemoteService
Cleans all previously configured expectations and requests history.
$I->dontExpectRequestsInRemoteService();
haveCleanScenariosInRemoteService
Cleans the state of all scenarios (sets all of them to inital state).
$I->haveCleanScenariosInRemoteService();
seeRemoteServiceReceived
Allows you to verify that the server received a request a given amount of times. This request could or not be previously set up as an expectation.
$I->seeRemoteServiceReceived(1, A::getRequest()->andUrl(Is::equalTo('/some/url')));
didNotReceiveRequestsInRemoteService
Resets the requests counter for the verifier in Phiremock.
$I->didNotReceiveRequestsInRemoteService();
Use case
Yii2-Curl
Yii2-Curl uses phiremock-codeception-extension for functional testing. You can see the configuration for the extension and the module, as well as how Phiremock is configured in the tests.
phiremock/phiremock-codeception-extension 适用场景与选型建议
phiremock/phiremock-codeception-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 287 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「mock」 「extension」 「server」 「codeception」 「tests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phiremock/phiremock-codeception-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phiremock/phiremock-codeception-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phiremock/phiremock-codeception-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
repository php library
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 287
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2018-04-13