rdx/behat-variables
Composer 安装命令:
composer require rdx/behat-variables
包简介
Store variables across Scenarios during Behat testing
README 文档
README
Stores your custom variables across Scenarios during Feature testing.
The idea
You're making users and profiles to test, and you want to use those creations further in the same Feature. You can't, because: 1) Behat arguments are literals, and 2) FeatureContext lives only for every Scenario, not for the entire Feature.
With behat-variables, you can save & use those variables: user ids, passwords, activation tokens, etc.
Given a new user "Fred" # Your custom step, with a return value
And I save it into "UID" # A provided step that saves that return value
When I go to "/users/<<UID>>" # Custom step, with dynamic argument
Then I should see "Hello, Fred!" # Custom step, with predictable content
The <<UID>> part is the magic. Works for any argument, not just URIs.
Set up
In order to use variables in your Behat feature, you must do 2 things:
- Add the Feature Context class:
rdx\behatvars\BehatVariablesContext - Add the Extension class:
rdx\behatvars\BehatVariablesExtension
See the Behat docs for where they fit in behat.yml, or see this repo's behat.yml:
default:
suites:
default:
contexts:
- rdx\behatvars\BehatVariablesContext
- FeatureContext
extensions:
rdx\behatvars\BehatVariablesExtension: ~
And make sure your custom steps have a scalar return value, or an array of scalars:
/**
* @Given a value :value
*/
public function aValue($value) {
return $value;
}
/**
* @Given values :value1 and :value2
*/
public function valuesAnd($value1, $value2) {
return [$value1, $value2];
}
Examples
See features/simple.feature for very simple examples (with only 3 custom steps). It's the
test used to test this package.
Features
This package provides 1 step, in several formats:
(I|we) save (it|that|those|them) into "VARIABLE_NAME"
So you can make several custom step combinations:
Given "4" cars in the same shop # Custom
And we save those into "CAR1,CAR2,CAR3,CAR4" # Provided
Given a user "Fred" in organization "McDonald's" # Custom
And we save those into "USER,ORGANIZATION" # Provided
rdx/behat-variables 适用场景与选型建议
rdx/behat-variables 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.46M 次下载、GitHub Stars 达 12, 最近一次更新时间为 2016 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rdx/behat-variables 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rdx/behat-variables 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.46M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 16
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-27