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
- Merge pull request #181 from acidjazz/master support for phpunit 6.x — committed to laravel/dusk by taylorotwell 7 years ago
Do you have a
setUpmethod? If so, be sure to callparent::setup()as the first statement in that function.Removing (any)
dd()ordump()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!
Spaces in .env, without quotes are not valide. But this error msg is confusing.
Laravel’s
Unit/ExampleTest.phpextends PHPUnit’sTestCaseclass which doesn’t bootstrap the Laravel app obviously, so if you’re expecting app functionality likeconfig()you need to extendTests\TestCaselikeFeature/ExampleTest.phpdoes.PHPUnit 6.0 is the problem here. I upgraded to it too and methods annotated with
@beforeget 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…
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 fineAlso check if you accidentally extended wrong TestCase class with your test class.
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
Sometime you will get this error if your test function run in a separate process.
go to the .env file. Make sure that the title contains no space or special character
Hope that this can help you too
https://github.com/barryvdh/laravel-dompdf/issues/192#issuecomment-414139013
I was have the same problem. Solution:
Check your
TestCase.php, content:Off course, you need this file on the same folder
CreatesApplication.php.