Configure behat with Symfony2

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 16:14:40

问题


I'm trying to configure Behat, but I have some errors. Here is config:

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

Import to config.yml. And when I try run clear:cache or bin/behat I getting:

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

I do all steps what described here: behat docs What I am doing wrong?


回答1:


I'm sharing what I have been using for all my Symfony2 projects. Behat+Mink+Selenium

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

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

SELENIUM

Download into your project. It is here, make sure you download 2.43.1 version which is in the middle of the page.

Run it: java -jar selenium-server-standalone-2.43.1.jar

CONTEXT FEATURE

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
}

TESTS

When you have feature files you can run them like this (this runs all in one go. for more info read behat doc):

bin/behat @SiteCommonBundle



回答2:


You don't need to import behat.yml in your config.yml.

Behat works independently from Symfony. And these configs cannot be messed. In the documentation from link that you provide you can find that behat.yml must be located at the project's root folder.



来源:https://stackoverflow.com/questions/27542896/configure-behat-with-symfony2

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