Laravel和PHPUnit:未找到Laravel包中的测试用例
我目前正在开发一个小软件包,并希望为其添加测试,但不知何故,我的软件包的类Laravel和PHPUnit:未找到Laravel包中的测试用例,php,laravel,phpunit,Php,Laravel,Phpunit,我目前正在开发一个小软件包,并希望为其添加测试,但不知何故,我的软件包的类TestCase找不到 以下是错误消息: PHP Fatal error: Uncaught Error: Class 'Tjventurini\GetRelationshipKey\Tests\TestCase' not found in /home/vagrant/code/get-relationship-key.local/packages/get-relationship-key/tests/BelongsTo
TestCase
找不到
以下是错误消息:
PHP Fatal error: Uncaught Error: Class 'Tjventurini\GetRelationshipKey\Tests\TestCase' not found in /home/vagrant/code/get-relationship-key.local/packages/get-relationship-key/tests/BelongsToUserTest.php:5
这是我的作曲家文件:
{
"name": "tjventurini/get-relationship-key",
"description": "Trait and sample configuration to manage model relationships via configurations.",
"type": "package",
"keywords": [
"tjventurini",
"laravel",
"eloquent",
"get-relationship-key"
],
"license": "MIT",
"authors": [
{
"name": "Thomas Venturini",
"email": "me@example.com"
}
],
"require": {
"illuminate/support": "^6.0"
},
"autoload": {
"psr-4": {
"Tjventurini\\GetRelationshipKey\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tjventurini\\GetRelationshipKey\\Tests\\": "tests/"
}
}
}
以下是我的文件结构的屏幕截图:
引发错误的测试:
好的,我发现我的composer.josn
文件中的autoloaddev
属性只适用于根包。这意味着在创建自动加载文件时不应用它
为了解决这个问题,我只是将测试名称空间移动到我的正常自动加载列表中,它就可以工作了
"autoload": {
"psr-4": {
"Tjventurini\\GetRelationshipKey\\Tests\\": "tests/",
"Tjventurini\\GetRelationshipKey\\": "src/"
}
}
很简单,但它能工作 您是否在包目录中运行了composer dump autoload
?为什么要在包目录中运行此操作?它应该与laravel项目的其他部分使用相同的自动加载。无论如何我都试过了,但是运气不好……您必须像这样导入TestCase
类:use Tests\TestCase代码>。查看这些以了解更多信息。我不想使用来自laravel的TestCase类,而是我自己的。由于它与扩展它的类位于同一目录中,所以我不必为它声明use语句。
"autoload": {
"psr-4": {
"Tjventurini\\GetRelationshipKey\\Tests\\": "tests/",
"Tjventurini\\GetRelationshipKey\\": "src/"
}
}