如何将 Behat 配置为从我的应用特定文件夹自动加载 类

How do I configure Behat to autoload classes from my app specific folder

我正在尝试在我现有的一个小项目上安装和配置 Behat。我理解将 *.feature 文件放入 features 文件夹的概念,也可以接受将我实际的 *Context.php 文件放入 features/bootstrap 文件夹。当我查看文档中提到实际功能实现的部分时,它暗示 Behat 默认情况下希望您将特定于应用程序的 classes 放入同一文件夹中:

We put the Shelf class into features/bootstrap/Shelf.php because features/bootstrap is an autoloading folder for Behat. Behat has a built-in PSR-0 autoloader, which looks into features/bootstrap. If you’re developing your own application, you probably would want to put classes into a place appropriate for your app.

但是它在文档中的任何地方都没有提到我将如何配置 Behat 以便能够从实际的 app 文件夹中识别 classes。

这是我的项目目录结构:

/
-/app
--/classes --where my apps classes actually live
-/features --behat generated folder
--/bootstrap --behat generated folder
-/public
-/system
-/vendor -- composer included libraries

我的项目使用它自己的 classes 自动加载器,它在 app/classes 文件夹中搜索,并且 class 名称使用下划线,其中目录分隔符将在路径中。例如class Controller_App 将在 app/classes/controller/app.php

中找到

如何配置 Behat,使其不会在 features/bootstrap 文件夹中找到我的应用程序 classes?

解决方案是将以下内容添加到 composer.json

"autoload": {
        "psr-0": {"":"app/classes"}
}

然后是运行composer dump-autoload

那么就可以了!