如何将Behat.yml中的参数获取到php文件中?
我有一个行为如何将Behat.yml中的参数获取到php文件中?,php,behat,mink,Php,Behat,Mink,我有一个行为 default : context : parameters : user: xyz password : abc 此外,我还有一个名为FeatureContext.php的文件,该文件通过从behat.yml检索值 public function iExample($user, $password) { $userName=$this->getParameter($us
default :
context :
parameters :
user: xyz
password : abc
此外,我还有一个名为FeatureContext.php的文件,该文件通过从behat.yml检索值
public function iExample($user, $password)
{
$userName=$this->getParameter($user);
}
但它会抛出一个错误,比如
"Call to undefined method FeatureContext::getParameter()"
我错过什么了吗。。我还通过以下方式在FeatureContext.php中添加了autoload.php
require_once __DIR__.'/../../vendor/autoload.php';
如果您知道发生这种情况的原因,请告知。您的
FeatureContext
类必须扩展BehatContext
,然后您将参数数组作为FeatureContext
的构造函数中的参数获取。有关示例,请参见
编辑:
我已经有一段时间没有使用Behat了,但您可能已经知道了。我也尝试过使用BehatContext。它给了我同样的错误。。。。“PHP致命错误:在第61行的D:\mypgms\reach\features\bootstrap\FeatureContext.PHP中调用未定义的方法FeatureContext::getParameter()”请参阅我编辑的答案。不要使用getParameter(它似乎不存在,我也无法从API文档中找到它),而是将参数保存到构造函数中的成员变量中,以供以后使用。
class FeatureContext extends BehatContext
{
private $params = array();
public function __construct(array $parameters)
{
$this->params = $parameters;
}
public function iExample($user, $password)
{
$userName = $this->params['user'];
}
}