PHPUnit \ DBUnit \名称空间未定义

时间:2018-04-07 01:06:44

标签: php namespaces phpunit

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

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

我运行了作曲家并更新了我的安装以包含dbunit(我已经有了PHPUnit)。

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

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

我错过了一步吗?

1 个答案:

答案 0 :(得分:2)

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

"phpunit/dbunit": "^1"

通过将版本增加到^ 4,命名空间不再是不可用的。请记住这一点,如果您还不了解作曲家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.

这是我用过的作曲家.json:

{
  "require-dev": {
    "phpunit/phpunit": "^7",
    "phpunit/dbunit": "^4"
  }
}
相关问题