【问题标题】:PHPUnit can't find my classes but autoload in composer.json looks finePHPUnit 找不到我的类,但 composer.json 中的自动加载看起来不错
【发布时间】:2021-04-20 04:17:18
【问题描述】:

我的 composer.json 中有以下内容:

"autoload": {
    "psr-4": {
        "Athena\\Core\\": "core",
        "Athena\\Tests\\": "tests",
    }
}

我有这个目录结构:

core/
    Framework/
        Console/
            Commands/
                AbstractCommand.php
tests/
    Console/
        Commands/
            AbstractCommandTest.php

在 PHPStorm 中运行测试时,我得到: 错误:找不到类 'Athena\Core\Framework\Console\Commands\AbstractCommand'

我想也许 vendor/autoload.php 没有被加载,但如果我尝试运行 phpunit tests --bootstrap vendor/autoload.php,我会收到错误消息说不能声明已经声明的东西,所以很明显它已经加载了。

发生了什么事? :S

【问题讨论】:

    标签: composer-php phpunit phpstorm


    【解决方案1】:

    事实证明,当运行全局安装的 phpunit 时,它会从 composers 安装位置加载供应商/自动加载,而不是项目。因此它无法加载任何项目类文件。

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 2016-02-17
      • 2017-01-02
      • 2018-04-29
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      相关资源
      最近更新 更多