meare / codeception-mountebank
此包已被废弃,不再维护。未建议替代包。
mountebank 与 Codeception 集成
v1.0
2017-01-29 17:49 UTC
Requires
- php: >=5.5
- codeception/codeception: ~2.0
- meare/juggler: ~1.0
Requires (Dev)
- phpunit/phpunit: ^4.0
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is auto-updated.
Last update: 2021-03-31 10:29:46 UTC
README
codeception-mountebank 提供了与mountebank的集成,该模块允许
- 配置测试运行所需的模拟器;
- 使用模拟器作为存根并验证是否已发出特定请求;
- 保存模拟器以供调试目的;
模块使用Juggler与 mountebank 交互,并在自定义辅助类或模块中完全控制 mountebank。
注意,目前仅支持 HTTP 模拟器。
安装
通过 Composer 需要模块
$ composer require meare/codeception-mountebank
配置
模块应在套件配置文件中启用和配置
class_name: AcceptanceTester modules: enabled: - Mountebank config: Mountebank: # mountebank host # Required host: 'localhost' # Port mountebank listens on # 2525 by default port: 2525 # Imposters configuration # All previous imposters are deleted before the run imposters: # Imposter alias xyz: # Path to imposter contract # Required contract: '_data/mountebank/xyz/stub.json' # Set this property to save imposter contract after tests run # Property value is path to save contract to save: '_output/mountebank/xyz/stub.json' # Set to true if imposter is used as mock # Mock imposters are restored from original contract after each test # Default: false mock: true
用法
模拟验证
使用模拟功能时,应使用--mock标志启动 mountebank
在套件配置中,模拟器的 mock 属性应设置为 true。这保证了在每个测试之前将模拟器恢复。恢复意味着从 mountebank 中删除现有的模拟器,并从配置中发布合约。这样做是为了清除模拟器记录的请求。
模块提供 3 种方法来验证模拟模拟器
seeImposterHasRequests($alias)
断言模拟器至少已记录 1 个请求
seeImposterHasRequestsByCriteria($alias, $criteria)
断言模拟器至少已记录 1 个满足条件的请求。
如果 $criteria 是数组,则如果 $criteria 是请求的子数组,则认为请求匹配,例如。
$I->seeImposterHasRequestsByCriteria('xyz', [ 'method' => 'GET', 'query' => [ 'account_id' => '7' ] ])
{ "protocol": "http", "port": 4646, "numberOfRequests": 1, "name": "xyz", "requests": [ { "requestFrom": "::ffff:127.0.0.1:57484", "method": "GET", "path": "/balance", "query": { "account_id": "7", "currency": "USD", }, "headers": { "Host": "localhost", "Connection": "close" }, "body": "", "timestamp": "2017-01-12T16:03:07.632Z" } ] }
更复杂的条件可以用回调表示。回调的签名是
/** * @var string $request decoded request object from contract JSON. * * @return bool Whether requests matches */ function(array $request) {}
回调将在模拟器拥有的每个请求上调用,直到返回 true。
seeImposterHasNoRequests($alias)
断言模拟器上没有记录请求。
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
贡献
请参阅CONTRIBUTING和CONDUCT以获取详细信息。
致谢
许可协议
MIT许可协议(MIT)。有关更多信息,请参阅许可文件。