【问题标题】:Configure behat with Symfony2使用 Symfony2 配置 behat
【发布时间】:2014-12-23 18:10:31
【问题描述】:

我正在尝试配置 Behat,但出现了一些错误。这是配置:

default:
suites:
  default:
      contexts:
          - FeatureContext:
              session:   '@session'
extensions:
  Behat\Symfony2Extension: ~
  Behat\MinkExtension:
      sessions:
      default:
      symfony2: ~

导入到 config.yml。当我尝试运行 clear:cache 或 bin/behat 我得到:

 There is no extension able to load the configuration for "default" (in /var/www/ontheway/app/config/behat.yml). Looked for namespace "default", found "framework", "security", "twig", 

我执行此处描述的所有步骤: behat docs 我做错了什么?

【问题讨论】:

  • 这是您创建的确切 YML 吗?如果是这样,那么它在第二行的缩进不正确。在那里你应该有另一个缩进级别。

标签: symfony testing behat


【解决方案1】:

我正在分享我在所有 Symfony2 项目中一直使用的东西。贝哈特+貂皮+硒

作曲家:

mySymfonyProject/composer.json:

"require": {
    "behat/behat": "2.5.*@stable",
    "behat/behat-bundle": "1.0.0",
    "behat/symfony2-extension": "1.1.2",
    "behat/mink": "1.5.0",
    "behat/mink-extension": "~1.3",
    "behat/mink-selenium2-driver": "1.1.1",
    "behat/mink-goutte-driver": "1.0.9"
},
"config": {
    "bin-dir": "bin"
},
"minimum-stability": "dev",

BEHAT

mySymfonyProject/behat.yml:

default:
    context:
        class: FeatureContext
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true
        Behat\MinkExtension\Extension:
            base_url: 'http://mysymfonyproject.local/app_test.php/'
            javascript_session: selenium2
            browser_name: firefox
            goutte: ~
            selenium2: ~
    paths:
        features: %behat.paths.base%/src
        bootstrap: %behat.paths.features%/Context

下载到您的项目中。是here确保您下载的是页面中间的 2.43.1 版本。

运行它:java -jar selenium-server-standalone-2.43.1.jar

上下文特征

mySymfonyProject/src/Site/CommonBundle/Features/Context/FeatureContext.php

<?php

namespace Site\CommonBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class FeatureContext extends MinkContext implements KernelAwareInterface
{
    /**
     * Hold Symfony kernel object.
     *
     * @var object Kernel Object.
     */
    protected $kernel;

    /**
     * Helps to use doctrine and entity manager.
     *
     * @param KernelInterface $kernelInterface Interface for getting Kernel.
     */
    public function setKernel(KernelInterface $kernelInterface)
    {
        $this->kernel = $kernelInterface;
    }

    //And your own methods
}

测试

当您拥有功能文件时,您可以像这样运行它们(一次运行。有关更多信息,请阅读 behat doc):

bin/behat @SiteCommonBundle

【讨论】:

    【解决方案2】:

    您无需在config.yml 中导入behat.yml

    Behat 独立于 Symfony 工作。而且这些配置不能乱七八糟。在您提供的链接文档中,您可以发现behat.yml 必须位于项目的根文件夹中。

    【讨论】:

    • 哎呀。这看起来很像正确答案。我没有注意到 @Panzer_Commander 正在导入 YML。
    • 好的,我排除了将 behat,eml 导入到配置中。但是现在当我运行 bin/behat 我得到这个错误``FeatureContext` context class not found and can't be used.`
    • 您是否将FeatureContext.php 放入PROJECT_ROOT/features/Context
    • 另外,如果你真的有错误的缩进(你的缩进与文档中的不同),它可能会被错误地解析。如果您有正确的缩进,请在您的问题中修复它。
    猜你喜欢
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多