How can i get the Parameters from Behat.yml to a php file?

别等时光非礼了梦想. 提交于 2019-12-18 17:29:25

问题


I have a Behat.yml

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

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);
    }

But it throws an error like

   "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 ?


回答1:


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.

Edit:

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

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

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

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



来源:https://stackoverflow.com/questions/20879472/how-can-i-get-the-parameters-from-behat-yml-to-a-php-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!