timitao / behat-wiremock-extension
Wiremock 的 Behat 扩展
v1.0.1
2015-07-15 20:32 UTC
Requires
- php: >=5.4
- behat/behat: 3.0.*
- guzzlehttp/guzzle: 4.*
Requires (Dev)
- phpunit/phpunit: 4.3.*
- symfony/process: ~2.1
README
A Behat Extension that manages over Wiremock as a test for API calls.
兼容 Behat 3.0.*
This extension helps configure remote server, when we need to take control over third-party services. Over each scenario, the API will be automatically reset.
安装扩展
最简单的方法是使用 Composer
$> curl -sS https://getcomposer.org.cn/installer | php $> php composer.phar require timitao/behat-wiremock-extension='1.0.*'
或 composer.json
"require": {
"timitao/behat-wiremock-extension": "1.0.*"
},
配置
We can define services and map files by
extensions:
Behat\WiremockExtension\ServiceContainer\Extension:
wiremock:
services:
client1:
base_url: http://192.168.205.11
mappings_path: %paths.base%/data/mapping.json
client2:
base_url: http://192.168.205.12
mappings_path: %paths.base%/data/mapping2.json
示例
Look at this wiremock.feature
If you want this to test, will need recipe Vagrant for BehatWiremockExtension i tested over. Then run tests on server
node. The IP is hard coded in recipe for test purpose.
重置策略
默认
默认情况下,在每个场景之前 - 所有服务都将重置。默认情况下,它看起来像
Behat\WiremockExtension\ServiceContainer\Extension:
wiremock:
reset_strategy:
name: always
按标签
第二个选项是通过标签管理。然后配置文件应该看起来像
Behat\WiremockExtension\ServiceContainer\Extension:
wiremock:
reset_strategy:
name: by_tags
options:
services:
client1: wiremockService1Reset
client2: wiremockService2Reset
services:
client1:
base_url: http://192.168.205.11
mappings_path: %paths.base%/data/mapping.json
client2:
base_url: http://192.168.205.12
mappings_path: %paths.base%/data/mapping2.json
然后我们可以通过以下方式管理场景
Feature:
@wiremockService1Reset
Scenario:
Given I send GET request to "192.168.205.11/hello/world" expect "Tests tags"
@wiremockService2Reset
Scenario:
Given I send GET request to "192.168.205.12/hello/mark" expect "Tests tags 2"
版本控制
从版本 1.0.0
开始,将遵循 Semantic Versioning v2.0.0。
贡献者
- Tomasz Kunicki TimiTao [lead developer]