努力让Mink与Behat合作 [英] Struggling to get Mink working with Behat

查看:88
本文介绍了努力让Mink与Behat合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在遵循本指南(并通过composer安装了所有内容): http://docs.behat.org/cookbook/behat_and_mink.html ,并试图使Behat + Mink正常工作,但是每次尝试运行bin/behat时,都会出现以下错误:

I've been following this guide (and installed everything through composer): http://docs.behat.org/cookbook/behat_and_mink.html and am attempting to get Behat + Mink working but everytime I try and run bin/behat I get the following error:

PHP Fatal error:  Call to a member function getSession() on a non-object in vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 80

该行代码是:

return $this->getMink()->getSession($name);

所以由于某些原因,貂属性为空,但我不知道为什么.

So for some reason the mink attribute is empty but I've no idea why.

我的.feature文件与指南中的文件完全相同,FeatureContext类也来自指南:

My .feature file is exactly the same as the one in the guide, the FeatureContext class is also from the guide:

use Behat\Behat\Context\ClosuredContextInterface,
    Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
    Behat\Gherkin\Node\TableNode;     

use Behat\MinkExtension\Context\MinkContext;

/**
 * Features context.
 */
class FeatureContext extends MinkContext 
{

}

我的供应商/behat/mink/behat.yml文件包含:

and my vendor/behat/mink/behat.yml file contains:

context:
  extensions:
    Behat\MinkExtension\Extension:
      base_url:  'http://en.wikipedia.org/'
      goutte:    ~
      selenium2: ~

我也尝试过让我的类扩展BehatContext,然后调用useContext,但这给了我同样的错误. Behat本身似乎可以正常工作,而Mink只会产生致命错误,而我不知道如何解决.

I've also tried making my class extend BehatContext and then call useContext but that gives me the same error. Behat itself seems to work it's just anything with Mink produces that fatal error and I've no idea how to fix it.

推荐答案

这是因为您应该将vendor/behat/behat/behat.yml.dist文件复制到your/project/root/behat.yml,而不是在供应商目录中编辑该文件并将extesions添加到部分.

This is because you should copy vendor/behat/behat/behat.yml.dist file to your/project/root/behat.yml, rather than editing the file in the vendor dir and add extesions to the default section.

这是它的样子:

default:
  extensions:
    Behat\MinkExtension\Extension:
      base_url: http://lunch-time/app_dev.php
      goutte: ~
      selenium2: ~

  paths:
    features:  features
    bootstrap: features/bootstrap

annotations:
  paths:
    features: features/annotations

closures:
  paths:
    features: features/closures

这篇关于努力让Mink与Behat合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆