这是我的目录结构:
composer.json
composer.phar
vendor/
bin/
behat
tests/
functional/
behat.yml
features/
registration.feature
bootstrap/
FeatureContext.php
我做到了:
cd tests/functional
../../vendor/bin/behat --init
这为我创建了基本结构。这是在 behat.yml 中:
default:
paths:
features: '%behat.paths.base%/features'
bootstrap: '%behat.paths.base%/features/bootstrap'
现在我尝试像这样运行 BDD 测试:
vendor/bin/behat -c tests/functional/behat.yml
然后我得到:
[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]
知道问题出在哪里吗?
我通过 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"
}
}
我安装的是:
php composer.phar install --dev -o
最佳答案
您在 tests/functional
目录中初始化了 Behat,但您试图从根目录运行它。
修正你的路径:
default:
paths:
features: 'tests/functional/features'
bootstrap: 'tests/functional/features/bootstrap'
或者从 tests/functional
目录运行 Behat。
我建议保留原始文件布局(根目录中的功能)。 编辑:实际上,我尝试自己设置它并且它与您提供的配置一起工作。一定有您正在做的其他事情,但您没有在问题中指定。
关于php - Behat - 未找到上下文类。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15929123/