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
The full composer.lock can be seen https://gist.github.com/OwenMelbz/c05172b33f6eb4483e37a56469b53722
Fingers crossed you guys have some ideas!
Cheers :)
I've noticed this too. Currently seeing if I can track down what change caused this. I thought it was the @before annotation on the method that calls ->baseUrl() but that has been like that for 2 months according to GitHub so I'm not sure what it is.
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.
@thecrypticace PR would be awesome :)
Subbed: Having the same issues with PHPUnit 6.0.
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.
@thecrypticace any luck?
Hello guys, can you give us an update on the progress till so far?
Any update on this bug? Still affecting latest versions.
Any workaround for this? Other than downgrading phpunit to 5.0
Following for a fix for phpunit 6.0
Thanks @tomfordweb for bumping this.
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.
I just ran into this as well, adding quotes fixed it. The error message really isn't helpful.
@moxx it worked for me.
Thanks!!
Had same problem and i've deleted bootstrap/cache/config.php and ran php artisan clear-compiled , now it's working fine
Do you have a setUp method? If so, be sure to call parent::setup() as the first statement in that function.
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.
Hope that this can help you too
https://github.com/barryvdh/laravel-dompdf/issues/192#issuecomment-414139013
go to the .env file. Make sure that the title contains no space or special character
Do you have a
setUpmethod? If so, be sure to callparent::setup()as the first statement in that function.
i got this problem, now reslove by add code parent::setUp()
saved my day after adding parent::setUp()
Sometime you will get this error if your test function run in a separate process.
```php
/**
Had same problem and i've deleted bootstrap/cache/config.php and ran
php artisan clear-compiled, now it's working fine
sangat bagus sekali
Removing (any) dd() or dump() lines in the application fixed the issue for me.
Do you have a
setUpmethod? If so, be sure to callparent::setup()as the first statement in that function.
I just want to point out how that looks like in a source file.
Below you can see a situation which causes the ReflectionException.
class MyFirstTest extends TestCase
{
public function setUp() {
$resourceObject = new ResourceObjectMock;
}
/**
* A basic test example.
*
* @return void
*/
public function testResource()
{
$this->assertTrue(true);
}
}
Below parent::setup(); is added to the setup method in the Test class.
This solution fixed the ReflectionException problem.
class MyFirstTest extends TestCase
{
public function setUp() {
parent::setup();
$resourceObject = new ResourceObjectMock;
}
/**
* A basic test example.
*
* @return void
*/
public function testResource()
{
$this->assertTrue(true);
}
}
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.
Also check if you accidentally extended wrong TestCase class with your test class.
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.
Also check if you accidentally extended wrong TestCase class with your test class.
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.
Thanks!
@Casmo Thank You. Removing dump( ) and dd( ) in different files related to the test has helped me to resolve the problem.
@Casmo Thank You. Removing dump( ) and dd( ) in different files related to the test has helped me to resolve the problem.
this fixed it for me
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
Most helpful comment
Do you have a
setUpmethod? If so, be sure to callparent::setup()as the first statement in that function.