jacekk / codeception-dataprovider-module
在Codeception测试中轻松管理数据。
v1.1.1
2017-01-30 16:32 UTC
Requires
- php: >=5.4
- codeception/codeception: 2.*
- jasny/dotkey: ^1.0
This package is not auto-updated.
Last update: 2024-09-28 19:42:01 UTC
README
此模块帮助您轻松管理测试中使用的数据。特别是,如果您喜欢Yaml/YML文件格式。
安装
将包添加到您的 composer.json 文件中
{ "require-dev": { "codeception/codeception": "2.*", "jacekk/codeception-dataprovider-module": "1.*" } }
告诉Composer下载此包
$ composer update
然后,在您的 my-awesome.suite.yml
配置中启用它,并调整两个必需参数,如此库配置
class_name: NoGuy modules: enabled: - Asserts - DataProvider config: DataProvider: dataPathTpl: '{root}/tests/_data/{file}' files: - common-provider.yml - env-provider.dev.yml
您需要重新构建您的actor类
$ php codecept.phar build
或者
$ vendor/bin/codecept build
或者您工具集允许的任何操作 :) 最后,查看 示例 部分,并每天使用它 :)
参数
dataPathTpl
用于构建通过适当设置列出的文件路径的模板。允许以下标记,其中第一个是必需的
{file}
- files 设置中的元素之一,{root}
- 当前工作目录 - PHP函数:getcwd()
。
files
一个或多个文件名,可以在定义在 dataPathTpl 下的路径中找到。如果频繁使用 --env
参数,则某些 files 重用是内置的。
使用示例
getValue($keyName, $default = null)
YML内容
headers: contentType: 'application/json' accept: 'text/html'
PHP代码
public function testSomeHeaders(NoGuy $I) { $headerValue = $I->getValue('headers.accept'); $I->assertEquals('text/html', $headerValue); // or with somethin not set in YML files $authType = $I->getValue('headers.authorizationType', 'Bearer'); $I->assertEquals('Bearer', $authType); }
iterateOver($keyName, callable $callback)
YML内容
users: admins: 0: id: 123 email: John(at)example.com fullName: John Example 1: id: 321 email: two(at)gmail.com fullName: Tom The Second
或(这也会起作用,即使它不是一个有序列表)
users: admins: - id: 111 email: mark(at)gmail.com fullName: Mark Whaleberg
PHP代码
public function testAdminsDataInUsersResource(NoGuy $I) { $I->iterateOver('users.admins', function ($user, $index) use ($I) { $userId = $user['id']; $I->sendGET("users/{$userId}"); $I->seeResponseContainsJson([ 'id' => $userId, 'is_admin' => true, 'email' => $user['email'], 'full_name' => $user['fullName'], ]); }); }
更多示例请参阅GetValueCest 和 IterateOverCest,它们验证此模块的质量。
许可证
与Codeception使用相同的许可证:MIT。