【问题标题】:How do I configure Behat to autoload classes from my app specific folder如何配置 Behat 以从我的应用程序特定文件夹中自动加载类
【发布时间】:2017-03-01 11:09:16
【问题描述】:

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

我们将 Shelf 类放入 features/bootstrap/Shelf.php 因为 features/bootstrap 是 Behat 的自动加载文件夹。贝哈特有一个 内置 PSR-0 自动加载器,它查看功能/引导程序。如果 您正在开发自己的应用程序,您可能希望将 类放到适合您的应用的位置。

但是文档中没有提到我将如何配置 Behat 以便能够识别来自实际 app 文件夹的类。

这是我的项目目录结构:

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

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

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

【问题讨论】:

    标签: php tdd bdd behat


    【解决方案1】:

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

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

    然后运行composer dump-autoload

    然后就可以了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多