ivashkevitch/codeception-wiremock-extension
Composer 安装命令:
composer require ivashkevitch/codeception-wiremock-extension
包简介
Wiremock extension for Codeception
README 文档
README
This Codeception Extension allows developers and testers to use WireMock to mock external services when running codeception tests.
codeception-wiremock-extension connects to an already running instance of WireMock or can also run automatically a local standalone one. And, it is able to download the version of wiremock you preffer and run it too. After the tests are finished it will close the connection and turn wiremock service off (when it started it).
See also
Note
If you need an application with a functionality that is similar to the one offered by WireMock and is 100% PHP, please give Phiremock a try: Phiremock, it also has a nice codeception extension.
Installation
Composer:
This project is published in packagist, so you just need to add it as a dependency in your composer.json:
"require": { // ... "mcustiel/codeception-wiremock-extension": "*" }
If you want to access directly to this repo, adding this to your composer.json should be enough:
{ "repositories": [ { "type": "vcs", "url": "https://github.com/mcustiel/codeception-wiremock-extension" } ], "require": { "mcustiel/codeception-wiremock-extension": "dev-master" } }
Or just download the release and include it in your path.
Configuration Examples
Module
The module allow you to connect to a WireMock instance, it can be the one ran by the extension or an already running one.
# acceptance.suite.yml modules: enabled: - WireMock: host: my.wiremock.host # defaults to 127.0.0.1 port: 80 # defaults to 8080
Extension
Default configuration
This configuration will download WireMock version 1.57 and run it on port 8080, writing logs to codeception tests _output dir.
# codeception.yml extensions: enabled: - Codeception\Extension\WireMock
Connect to a running WireMock instance
# codeception.yml extensions: enabled: - Codeception\Extension\WireMock config: Codeception\Extension\WireMock: host: my.wiremock.server port: 8080
Start a local WireMock instance and run it with given command line arguments
# codeception.yml extensions: enabled: - Codeception\Extension\WireMock config: Codeception\Extension\WireMock: jar-path: /opt/wiremock/bin/wiremock-standalone.jar port: 18080 https-port: 18443 verbose: true root-dir: /opt/wiremock/root
Download a WireMock instance and run it with given command line arguments
# codeception.yml extensions: enabled: - Codeception\Extension\WireMock config: Codeception\Extension\WireMock: download-version: 1.57 port: 18080 https-port: 18443 verbose: true root-dir: /opt/wiremock/root logs-path: /var/log/wiremock
How to use
Prepare your application
First of all, configure your application so when it is being tested it will replace its external services with WireMock. For instance, if you make some requests to a REST service located under http://your.rest.interface, replace that url in configuration with the url where WireMock runs, for instance: http://localhost:8080/rest_interface.
Write your tests
// YourCest.php class YourCest extends \Codeception\TestCase\Test { public function _after(\AcceptanceTester $I) { $I->cleanAllPreviousRequestsToWireMock(); } // tests public function tryToTest(\AcceptanceTester $I) { $I->expectRequestToWireMock( WireMock::get(WireMock::urlEqualTo('/some/url')) ->willReturn(WireMock::aResponse() ->withHeader('Content-Type', 'text/plain') ->withBody('Hello world!')) ); // Here you should execute your application in a way it requests wiremock. I do this directly to show it. $response = file_get_contents('http://localhost:18080/some/url'); $I->assertEquals('Hello world!', $response); $I->receivedRequestInWireMock( WireMock::getRequestedFor(WireMock::urlEqualTo('/some/url')) ); } // Also, you can access wiremock-php library directly public function moreComplexTest() { $wiremockPhp = Codeception\Extension\WiremockConnection::get(); // Now you can use wiremock-php library } }
ivashkevitch/codeception-wiremock-extension 适用场景与选型建议
ivashkevitch/codeception-wiremock-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「mock」 「extension」 「codeception」 「wiremock」 「mock external services」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ivashkevitch/codeception-wiremock-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ivashkevitch/codeception-wiremock-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ivashkevitch/codeception-wiremock-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
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
Adds more BBCode
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2018-11-22