scibuff
2 weeks ago

Test error (only when running suite) - Target class [config] does not exist.

Posted 2 weeks ago by scibuff

I have a simple test class, with two tests

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class MyBasicTest extends TestCase {

    /** @test */
    public function test1(){
        dump( config('app.name') );
        dump( config('app.env') );
        $this->assertTrue(true);
    }

    /** @test */
    public function test2(){
        dump( config('app.name') );
        dump( config('app.env') );
        $this->assertTrue(true);
    }
}

when I run each test separately everything works fine, but when I test the entire class, I get Target class [config] does not exist.

 Tests\Unit\MyBasicTest::test2
Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist.

/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:807
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:687
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:796
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:633
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:781
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:119
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:275
/home/vagrant/code/apps/my-app/tests/Unit/MyBasicTest.php:30

Caused by
ReflectionException: Class config does not exist

/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:805
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:687
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:796
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:633
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:781
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:119
/home/vagrant/code/apps/my-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:275
/home/vagrant/code/apps/my-app/tests/Unit/MyBasicTest.php:30

Basically, it seems that if I call config more then once in the second test during the run, it throws the BindingResolutionException

p.s. when I do phpunit --filter test2 everything works just fine; the error happens only if I run phpunit --filter MyBasicTest

Any ideas?

p.s.2. of course, my real working app test which throws these errors is much more complex, but I've narrowed it down to this simple case (calling config twice from two different tests)

[email protected]: $ php artisan --version
Laravel Framework 7.10.3

Please sign in or create an account to participate in this conversation.