dusk: ReflectionException: Class config does not exist

Hi guys, 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
  • PHPUnit 6.0

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

Fingers crossed you guys have some ideas!

Cheers 😃

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 34 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Do you have a setUp method? If so, be sure to call parent::setup() as the first statement in that function.

Removing (any) dd() or dump() lines in the application fixed the issue for me.

I got this same issue, but not related to phpunit. The issue was I added values containing spaces to my .env file. If you have values contains spaces in your .env file, surround them with quotes and then it’ll be fixed.

if you run php artisan clear-compiled while having this issue, it will tell the solution 😉

same here!

MAIL_NAME=company - service
#fix is
MAIL_NAME="company - service"

Spaces in .env, without quotes are not valide. But this error msg is confusing.

Also check if you accidentally extended wrong TestCase class with your test class.

Laravel’s Unit/ExampleTest.php extends PHPUnit’s TestCase class which doesn’t bootstrap the Laravel app obviously, so if you’re expecting app functionality like config() you need to extend Tests\TestCase like Feature/ExampleTest.php does.

PHPUnit 6.0 is the problem here. I upgraded to it too and methods annotated with @before get called before setUp.

cc @taylorotwell afaict, it seems like the solution here would be to do the same thing you did with the testing traits and call them explicitly during setUp. Thoughts? I’ll open a PR if that is the route you would like to go.

Just want to note that in Laravel 5.8.35 with PHPUnit 7.5.17 this works…

protected function setUp(): void
{
    parent::setUp();
    // Do something
}

protected function tearDown(): void
{
    // Do something
    parent::tearDown();
}

Note: it’s critical to to run you code after parent::setUp(); and before parent::tearDown(); this was the only way I could get it to work.

Had same problem and i’ve deleted bootstrap/cache/config.php and ran php artisan clear-compiled , now it’s working fine

Also check if you accidentally extended wrong TestCase class with your test class.

Do you have a setUp method? If so, be sure to call parent::setup() as the first statement in that function.

i got this problem, now reslove by add code parent::setUp()

If I have time this evening I’ll investigate what it takes to make Dusk compatible with both. There’ll definitely be challenges because PHPUnit 6 was a rather big BC break.

Following for a fix for phpunit 6.0

Any workaround for this? Other than downgrading phpunit to 5.0

I’ve experienced the same thing. my fix is

//use PHPUnit\Framework\TestCase; // this alse causes ReflectionException: Class config does not exist
use Tests\TestCase; // this is the right one

Sometime you will get this error if your test function run in a separate process.

/**
* @runInSeparateProcess
*/
public function testMyTest()
{
  // Your test
}

go to the .env file. Make sure that the title contains no space or special character

I was have the same problem. Solution:

Check your TestCase.php, content:

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

Off course, you need this file on the same folder CreatesApplication.php.