php - Behat - 未找到上下文类。

标签 php zend-framework2 behat

这是我的目录结构:

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/

相关文章:

php - Behat 3 - 将参数(从导入的文件)传递给 FeatureContext 构造函数

php - 如何使用 Behat 和 Mink PHP 处理浏览器窗口或选项卡

php - 如何使用 stdclass 对象从数组中获取值?

php - token_get_all() 函数无法正常工作

php - 使用 ID auto_increment 创建 MySQLi 表返回语法错误

routes - 在 ZF2 控制台应用程序中使用 HTTP 路由

php - 无法打开输入文件 : composer. phar

php - Twig,呈现模板并将模板作为电子邮件、CSS 和一些缺少的 img 发送

php - 如何从 zendframework 2.0 数据库中检索特定值

iframe - 如何使用 Behat/Mink 切换到动态命名的 iframe