使用Symfony2配置behat

时间:2014-12-18 09:12:35

标签: symfony testing behat

我试图配置Behat,但是我有一些错误。这是配置:

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

导入到config.yml。当我尝试运行清除:缓存或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 我做错了什么?

2 个答案:

答案 0 :(得分:3)

我正在分享我用于所有Symfony2项目的内容。贝哈特+水貂+硒

<强> COMPOSER:

<强> 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",

<强>贝哈特

<强> 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 /站点/ CommonBundle /功能/背景/ 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
}

<强> TESTS

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

bin/behat @SiteCommonBundle

答案 1 :(得分:2)

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

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