Laravel Unit Tests cannot find namespaced class

时光毁灭记忆、已成空白 提交于 2020-01-16 05:51:30

问题


I have a pretty basic Laravel setup that I am starting to test. I have my own library files in the folder app/framework and all the files are under the namespace "CompanyName\Framework". I added these files to the composer.json file to have it autoloaded in my app.

My composer.json is then :

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

In my controller I can use my library fine and autoloading seems to work. When I try to test that controller in my unit test it says

....PHP Fatal error: Class 'CompanyName\Framework\DatabaseUpdater' not found in C:\ Production\CompanyName\laravel\app\controllers\DatabaseController.php on line 19

Why is that namespace suddently invalid when I call my controller from my unit test ? The unit test itself is very basic, it is simply a $this->client->request('GET', '/'). Absolutely everything works perfectly except the unit test.

来源:https://stackoverflow.com/questions/22517218/laravel-unit-tests-cannot-find-namespaced-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!