【问题标题】:PHPUnit\DBUnit\ namespace not definedPHPUnit\DBUnit\ 命名空间未定义
【发布时间】:2018-09-17 01:46:35
【问题描述】:

我更新了我的 composer.json 文件以包含 dbunit:

"require-dev": {
    "phpunit/phpunit": "^7",
    "phpunit/dbunit": "^1"
},

我运行了 composer,它更新了我的安装以包含 dbunit(我已经有 PHPUnit)。

但是当我尝试将 TestCaseTrait 命名空间添加到我的测试时,IDE 声称它找不到该命名空间。

use PHPUnit\Framework\TestCase;      <----- this works great
use PHPUnit\DbUnit\TestCaseTrait;    <----- error that namespace doesn't exist

我错过了一步吗?

【问题讨论】:

    标签: php namespaces phpunit


    【解决方案1】:

    我能够在我的 composer.json 中重现您的问题:

    "phpunit/dbunit": "^1"
    

    通过将版本增加到 ^4,命名空间不再无法找到。请记住这一点,如果您还不了解 composer json 架构:

     The caret will update you to the most recent major version (the first number).
     ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
    

    这是我使用的工作 composer.json:

    {
      "require-dev": {
        "phpunit/phpunit": "^7",
        "phpunit/dbunit": "^4"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-21
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 2013-06-03
      • 2016-03-29
      • 2013-06-12
      • 2016-07-19
      • 1970-01-01
      相关资源
      最近更新 更多