php - 是否可以在代码接收示例中使用注释中的常量
问题描述
对于 codeception,有没有办法使用 @example 注释来使用常量(或变量)?我知道我们可以使用学说风格的注释。
数据通过 @example 注释定义,使用 JSON 或 Doctrine 样式的表示法(限于单行)。教义式
class PageCest { /** * @example(url="/", title="Welcome") * @example(url="/info", title="Info") * @example(url="/about", title="About Us") * @example(url="/contact", title="Contact Us") */ public function staticPages(AcceptanceTester $I, \Codeception\Example $example) { $I->amOnPage($example['url']); $I->see($example['title'], 'h1'); $I->seeInTitle($example['title']); } }
但是使用一个在教义中起作用的常数似乎在这里不起作用
/**
* @example(url=Class::Constant, title="Welcome")
*/
有没有办法实现这一点来运行多个测试示例但使用常量或变量来提供值?
解决方案
似乎没有办法像学说的实施那样直接做到这一点。我发现的解决方法是将常量名称作为字符串传递。
/**
* @example(url="MyConstantName", title="Welcome")
*/
然后在代码中使用常量函数来找到你的常量值。
constant('Full\Namespace\MyClass::' . $example['MyConstantName'])
推荐阅读
- python-3.x - Python 3 将一串键转换为同一行的值
- javascript - react.js 项目中的警告
- javascript - 反应路由器dom,使用id更改时组件不会被卸载
- ios - 计算动态标题大小时,在 reloadData 上重置滚动位置
- python - 如何向 setup.cfg 添加注释?
- amazon-web-services - 是否可以在通过命令行创建之前运行发现 AWS Cognito OIDC IdP?
- javascript - 在 React DatePicker 中插入当前 GMT 时间
- c# - WPF ScrollBar 未显示在 Grid 上
- android - 当我在 Jetpack Compose 中显示多个片段的选项卡布局时如何显示/隐藏弹出窗口?
- visual-studio - 如何在客户端 PC 上运行我的项目而不在客户端 PC 上安装 SQL Server