加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何从Behat.yml获取参数到php文件?

发布时间:2020-12-13 21:50:25 所属栏目:PHP教程 来源:网络整理
导读:我有一个Behat.yml default : context : parameters : user: xyz password : abc 我还有一个名为FeatureContext.php的文件,它从behat.yml中检索值 public function iExample($user,$password) { $userName=$this-getParameter($user); } 但它会抛出一个错误
我有一个Behat.yml

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的构造函数中将parameters-array作为参数.有关示例,请参见 http://michaelheap.com/behat-selenium2-webdriver/.

编辑:

class FeatureContext extends BehatContext
{
    private $params = array();

    public function __construct(array $parameters)
    {
        $this->params = $parameters;
    }

    public function iExample($user,$password)
    {
        $userName = $this->params['user'];
    }
}

我有一段时间没有使用过Behat,但你可能已经明白了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读