Laravel Dusk - 类配置不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42025231/
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 15:15:41  来源:igfitidea点击:

Laravel Dusk - Class config does not exist

phplaravellaravel-dusk

提问by Owen

recently upgraded a 5.3 project to 5.4 and all seemed good.

最近将 5.3 项目升级到 5.4,一切看起来都不错。

Today I started to implement Dusk however had hit an issue when running the example test

今天我开始实现 Dusk 但是在运行示例测试时遇到了问题

?  footy-finance [5.4] ? php artisan dusk
PHPUnit 6.0.0 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 162 ms, Memory: 6.00MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
ReflectionException: Class config does not exist

/Users/owen/Sites/footy-finance/vendor/laravel/framework/src/Illuminate/Container/Container.php:681
/Users/owen/Sites/footy-finance/vendor/laravel/framework/src/Illuminate/Container/Container.php:565
/Users/owen/Sites/footy-finance/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:105
/Users/owen/Sites/footy-finance/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:263
/Users/owen/Sites/footy-finance/vendor/laravel/dusk/src/TestCase.php:203
/Users/owen/Sites/footy-finance/vendor/laravel/dusk/src/TestCase.php:40

I've had a look at line 40 of TestCase.phpand its

我看过第 40 行TestCase.php和它的

public function baseUrl()
{
    return config('app.url');
}

So it does look like something to do with the global confighelper anybody have any ideas?

所以它看起来确实与全局config助手有关,有人有任何想法吗?

I'm running

我在跑

  • PHP 7.0.14
  • Laravel/Framework 5.4.8
  • Laravel/Dusk 1.0.5
  • PHP 7.0.14
  • Laravel/框架 5.4.8
  • Laravel/黄昏 1.0.5

The full composer.lock can be seen https://gist.github.com/OwenMelbz/c05172b33f6eb4483e37a56469b53722

完整的 composer.lock 可以看到https://gist.github.com/OwenMelbz/c05172b33f6eb4483e37a56469b53722

Fingers crossed you guys have some ideas!

手指交叉你们有一些想法!

Cheers :)

干杯:)

采纳答案by Owen

For anybody else who has had this issue.

对于遇到此问题的任何其他人。

I had prefer stable set in the composer file, which installed PHPUnit 6.

我更喜欢在 Composer 文件中设置稳定版,该文件安装了 PHPUnit 6。

This was "made stable today" - thus it installed during a composer update.

这是“今天稳定” - 因此它在作曲家更新期间安装。

Downgrading to PHPUnit 5 fixes the issue - so was bad timing starting it today.

降级到 PHPUnit 5 解决了这个问题——所以今天开始的时机很糟糕。

回答by Petar Vasilev

I had this error in the log

我在日志中有这个错误

Class config does not exist

the problem with me was that in the .env file I had set a configuration variable in the following way:

我的问题是在 .env 文件中我以下列方式设置了一个配置变量:

APP_NAME=Application Name

note the space. When I changed it to this:

注意空间。当我把它改成这样:

APP_NAME="Application Name" 

the problem got fixed

问题得到解决

回答by kibet H

The issue is with .env file App_Name

问题在于 .env 文件 App_Name

in the original file its written this way>>> APP_NAME=Application Name

在原始文件中这样写>>> APP_NAME=应用程序名称

Make it like this APP_NAME="Application Name"

像这样 APP_NAME="应用程序名称"

回答by Arnaud Bouchot

I just ran into the the same issue, in my case the .env was all clean, no unwrapped empty spaces.

我刚刚遇到了同样的问题,就我而言,.env 很干净,没有展开的空白空间。

This error message can also occur when writting/debugging a test case, using the setup()method in that test, forgetting to call parent::setup()as the first statement in that function.

当使用该setup()测试中的方法编写/调试测试用例时,忘记调用parent::setup()该函数中的第一个语句时,也会出现此错误消息。

protected $stuf;

function setup() {
    parent::setup();

    $this->stuf = 'stuf';
}

I found very useful info hereon what else could happen when you're getting this error message.

我在这里找到了非常有用的信息,了解当您收到此错误消息时还会发生什么。

回答by simonhamp

I had this in a Lumen application today. After some investigation and playing around, I found that it was because in PHPStorm it was adding the --no-configurationoption onto the phpunitcommand because I hadn't configured my PHPUnit setup for the project in the IDE.

我今天在 Lumen 应用程序中有这个。经过一番调查和尝试,我发现这是因为在 PHPStorm 中,它正在将--no-configuration选项添加到phpunit命令中,因为我没有在 IDE 中为项目配置 PHPUnit 设置。

I corrected that by clicking 'Run > Edit Configurations' and then under 'Defaults > PHPUnit' click the little button to the far right of the 'Use alternative configuration file:' option and set the 'Default configuration file:' to the full path to your project's phpunit.xml.

我通过单击“运行”>“编辑配置”,然后在“默认值> PHPUnit”下单击“使用替代配置文件:”选项最右侧的小按钮并将“默认配置文件:”设置为完整路径来纠正该问题到您的项目的phpunit.xml.

Hope this helps!

希望这可以帮助!

回答by Jim OHalloran

I've also had this issue. For me it was caused by calling the config()function inside a dataProvider method. DataProviders are called before the createApplication()method initialises the application, and populates the DI container. Hence config()fails because the app('config')call in the helper function can't resolve the configclass from the container.

我也遇到过这个问题。对我来说,它是由调用config()dataProvider 方法中的函数引起的。在createApplication()方法初始化应用程序之前调用 DataProviders ,并填充 DI 容器。因此config()失败,因为app('config')辅助函数中的调用无法config从容器解析类。