类'..\Unit\UnitTestCase'未找到。

3
我正在将laravel5.5.*升级到5.6.0,Composer安装没有问题。我试图运行单元测试,但出现了以下错误:

找不到类“..\Unit\UnitTestCase”

这是错误的堆栈跟踪:

致命错误:未捕获的错误:在/home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php的第11行中未找到类'PhiraterTest\Unit\UnitTestCase' 堆栈跟踪: #0 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(64):include_once() #1 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(48):PHPUnit\Util\Fileloader ::load('/home/vagrant/c...') #2 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(325):PHPUnit\Util\Fileloader ::checkAndLoad('/home/vagrant/c...') #3 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(403):PHPUnit\Framework\TestSuite- > addTestFile('/home/vagrant/c...') #4 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(65):PHPUnit\Framework\TestSuite- > addTestFiles(Array) #5 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/TextUI/Command.php(169):PHPUnit\Runner\BaseTestRunner- > getTest('tes在/home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php中的第11行

我的单元测试在tests/ 目录中。我的UnitTestCase 类通过 \TestCase 类进行扩展, TestCase 类通过 BrowserKitTestCase 进行扩展。我做错了什么?可能的解决方案是什么?

运行composer dump-autoload,问题就会得到解决。 - STA
@STA 已经完成了! - Saani
你是否已经在Composer中添加了以下内容:"autoload": { "psr-4": { "Tests\\": "tests/" } } - Ankit Jindal
请看这里:https://laracasts.com/discuss/channels/laravel/php-fatal-error-class-testcase-not-found - Zia Yamin
@AnkitJindal 是的,我有。 - Saani
这个链接有帮助吗? - Alexandre Elshobokshy
1个回答

1
如果您的依赖类确实存在并具有适当的命名空间,则上述错误出现的最有可能的原因是(避免将下面的示例复制到您的项目中,那肯定不起作用):
  • composer.json file (root directory) has no relevant record of the dependency (do not forget composer.lock file also), smth like:

    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    
  • as a result of above, vendor/autoload.php file (or any of its merged siblings, e.g. vendor/composer/autoload_classmap.php, depending on your case) can miss relevant record of the dependency, smth like:

      return array(
          'PHPUnit\\Framework\\TestCase' => '/vendor/phpunit/phpunit/src/Framework/TestCase.php',
    
在大多数情况下,这实际上是由autoload.php功能提供的缺失依赖项所导致的,而这又是由composer出现故障引起的。因此,请尝试通过运行composer self-update来更新composer本身,然后通过composer update更新您的依赖项。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接