Behat - 找不到上下文类.

Ric*_*nop 6 php behat zend-framework2

这是我的目录结构:

composer.json
composer.phar
vendor/
    bin/
        behat
tests/
    functional/
        behat.yml
        features/
            registration.feature
            bootstrap/
                FeatureContext.php
Run Code Online (Sandbox Code Playgroud)

我做了:

cd tests/functional
../../vendor/bin/behat --init
Run Code Online (Sandbox Code Playgroud)

这为我创造了基本结构.这是在behat.yml里面:

default:
  paths:
    features: '%behat.paths.base%/features'
    bootstrap:  '%behat.paths.base%/features/bootstrap'
Run Code Online (Sandbox Code Playgroud)

现在我尝试运行这样的BDD测试:

vendor/bin/behat -c tests/functional/behat.yml
Run Code Online (Sandbox Code Playgroud)

我得到:

  [RuntimeException]                                                       
  Context class not found.                                                 
  Maybe you have provided wrong or no `bootstrap` path in your behat.yml:  
  http://docs.behat.org/guides/7.config.html#paths                         



behat [--init] [-f|--format="..."] [--out="..."] [--lang="..."] [--[no-]ansi] [--[no-]time] [--[no-]paths] [--[no-]snippets] [--[no-]snippets-paths] [--[no-]multiline] [--[no-]expand] [--story-syntax] [-d|--definitions="..."] [--name="..."] [--tags="..."] [--cache="..."] [--strict] [--dry-run] [--rerun="..."] [--append-snippets] [--append-to="..."] [features]
Run Code Online (Sandbox Code Playgroud)

不知道是什么问题?

我通过Composer安装了Behat.这是我的composer.json:

{
    "name": "hello",
    "description": "Hello World",
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3",
        "zendframework/zendframework": "2.1.4",
        "doctrine/common": "dev-master#d7987c96675e153638729383577090feed9854f1"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.14",
        "behat/behat": "2.4.*@stable"
    }
}
Run Code Online (Sandbox Code Playgroud)

我安装的是:

php composer.phar install --dev -o
Run Code Online (Sandbox Code Playgroud)

Jak*_*las 6

您在tests/functional目录中初始化Behat 但是您尝试从根目录运行它.

修复你的路径:

default:
  paths:
    features: 'tests/functional/features'
    bootstrap:  'tests/functional/features/bootstrap'
Run Code Online (Sandbox Code Playgroud)

或者从tests/functional目录运行Behat .

我建议保留原始文件布局(根目录中的功能). 编辑:实际上,我尝试自己设置它并使用您提供的配置.你必须做的其他事情你没有在问题中指明.


Ric*_*nop 3

这就是有效的。

cd tests/functional
../../vendor/bin/behat --init
cd ../../
vendor/bin/behat -c tests/functional/behat.yml
Run Code Online (Sandbox Code Playgroud)

有了这个配置文件:

default:
  paths:
    features: features
    bootstrap: features/bootstrap
Run Code Online (Sandbox Code Playgroud)