Laravel 4 PHP 致命错误:找不到类“Illuminate\Foundation\Testing\TestCase”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18172011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:15:23  来源:igfitidea点击:

Laravel 4 PHP Fatal error: Class 'Illuminate\Foundation\Testing\TestCase' not found

phpphpunitlaravel

提问by kemal

I get the following error when I run phpunit with Laravel 4.

当我使用 Laravel 4 运行 phpunit 时出现以下错误。

PHP Fatal error:  Class 'Illuminate\Foundation\Testing\TestCase' not found in 

composer.json

作曲家.json

    "require": {
    "laravel/framework": "4.0.*",
    "phpunit/phpunit": "3.7.*"
},

app.php

应用程序.php

   'Illuminate\Foundation\Testing\TestCase'

What ? should do?

什么 ?应该做?

采纳答案by Tim F

It looks like the autoload doesn't include the new requirement.

看起来自动加载不包括新要求。

Be sure to run composer updateto ensure that the file are downloaded and the autoloader is updated with that source.

请务必运行composer update以确保下载文件并使用该源更新自动加载器。

If the files were downloaded and 'installed' manually run php composer dump-autoloadto rebuild the autoload file.

如果文件已下载并“安装”,则手动运行php composer dump-autoload以重建自动加载文件。

回答by thefuzzy0ne

I just ran into the same problem, so I thought I'd post my solution, even though it might be a different solution to what you were after.

我刚刚遇到了同样的问题,所以我想我会发布我的解决方案,即使它可能与您所追求的解决方案不同。

I wanted to autoload my own libraries, so I added the following to my composer.json:

我想自动加载我自己的库,所以我在我的 composer.json 中添加了以下内容:

"autoload": {
    "psr-0": {
        "Fhc": "app"
    }
},

What I didn't realise was that just above that line was the following:

我没有意识到的是,就在该行上方的是以下内容:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
},

In essence, my modification had completely overridden the the code above. The solution was to merge the two together (as I should have done to begin with).

实质上,我的修改完全覆盖了上面的代码。解决方案是将两者合并在一起(正如我开始时应该做的那样)。

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "psr-0": {
        "Fhc": "app"
    }
},

Now it's all working as expected.

现在一切都按预期进行。

I hope this helps anyone else in the same situation.

我希望这可以帮助处于相同情况的其他人。

回答by emont01

Try to remove your "vendor" folder and the file named composer.lock after that run:

尝试在运行后删除您的“供应商”文件夹和名为 composer.lock 的文件:

composer install

Pay attention to the output produced by composer.

注意 Composer 产生的输出。