yml将参数获取到php文件

yml将参数获取到php文件

本文介绍了如何从Behat.yml将参数获取到php文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Behat.yml

I have a Behat.yml

  default :
     context :
       parameters :
            user: xyz
            password : abc

我还有一个名为FeatureContext.php的文件,该文件通过以下方式从behat.yml中检索值:

Also i have a file called FeatureContext.php which retrieves the values from behat.yml through

   public function iExample($user, $password)
    {
       $userName=$this->getParameter($user);
    }

但是会引发类似

   "Call to undefined method FeatureContext::getParameter()"

我错过了什么吗? ..我还通过

Am i missing something ? .. i have also added autoload.php in FeatureContext.php through

   require_once __DIR__.'/../../vendor/autoload.php';

请告知,如果您知道为什么会发生这种情况?

Please let know , if you have any idea why it is happening ?

推荐答案

您的FeatureContext类必须扩展BehatContext,然后在FeatureContext的构造函数中获取parameters-array作为参数.有关示例,请参见 http://michaelheap.com/behat-selenium2-webdriver/.

Your FeatureContext class has to extend BehatContext and then you get the parameters-array as an argument in the constructor of FeatureContext. See http://michaelheap.com/behat-selenium2-webdriver/ for an example.

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了,但是您可能会明白.

I haven't used Behat for a while, but you probably get the idea.

这篇关于如何从Behat.yml将参数获取到php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:15