10

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

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

☁  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.php and its

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

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

I'm running

  • PHP 7.0.14
  • Laravel/Framework 5.4.8
  • Laravel/Dusk 1.0.5

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

Fingers crossed you guys have some ideas!

Cheers :)

owenmelbz
  • 6,180
  • 16
  • 63
  • 113

9 Answers9

35

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:

APP_NAME=Application Name

note the space. When I changed it to this:

APP_NAME="Application Name" 

the problem got fixed

Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74
  • Thank you @PetarVasilev ... I have applied all possible solutions but nothing worked other than this. BTW, I had it on my Shared Hosting when I config:clear using Artisan::call('config:clear'). – Mohal Feb 01 '18 at 07:03
6

The issue is with .env file App_Name

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

Make it like this APP_NAME="Application Name"

kibet H
  • 61
  • 1
  • 3
5

In my case, this solution works:

1) Remove all contents of the bootstrap/cache folder
2) Run the composer dump command

3

For anybody else who has had this issue.

I had prefer stable set in the composer file, which installed 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.

owenmelbz
  • 6,180
  • 16
  • 63
  • 113
3

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

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.

protected $stuf;

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

    $this->stuf = 'stuf';
}

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

Arnaud Bouchot
  • 1,885
  • 1
  • 21
  • 19
2

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 config class from the container.

Jim OHalloran
  • 5,859
  • 2
  • 37
  • 57
1

I'm very late for the party here but for anyone experiencing the same issue with Laravel's unit test and none of the above solutions work, you can look into mine and see if this might help.

In my case, I was trying to call a method that will remove all the test keys that persisted in my Redis database when I run the unit test. The method is called in the tearDown method of the class. The error occurs because the parent constructor is called before the actual tearDown code is executed. That's the reason why I'm having the error.

Instead of this one......

/**
 * tearDown is executed after test stub
 */
protected function tearDown()
{
    parent::tearDown();

    $this->deleteTestKeys();
}

Change it to this one...

protected function tearDown()
{
    $this->deleteTestKeys();

    parent::tearDown();
}

In this case, the class' is not totally destroyed yet and the Laravel's config method will get called accordingly.

0

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-configuration option onto the phpunit command because I hadn't configured my PHPUnit setup for the project in the IDE.

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.

Hope this helps!

simonhamp
  • 3,078
  • 1
  • 20
  • 26
0

I saw this error after following some dodgy installation instructions for a third party module, which said to register a service provider in bootstrap/app.php

$app->singleton(...);
$app->singleton(...);
$app->register(\Third\Party\ServiceProvider::class);

This caused $this->app['config'] to generate the error BindingResolutionException: Target class [config] does not exist.

I fixed it by putting it in config/app.php, where it belongs:

/*
 * Package Service Providers...
 */
Third\Party\ServiceProvider::class,
mlambley
  • 13
  • 4