Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Corbin's avatar

Illuminate\Contracts\Container\BindingResolutionException Target class [config] does not exist.

I'm getting this error when I try to run a PHPUnit test that use model factories

use App\Models\Post;
use App\Models\Channel;

class ChannelTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function a_channel_has_many_posts() 
    {
        //$user ChannelCategory::factory()->create()->id;
        $channel = Channel::factory()->create();
        $post = Post::factory()->create(['channel_id' => $channel->id]);

        $this->assertTrue($channel->posts->contains($post));
    }
}

I've read in other threads to setup and teardown in the TestCase:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;

    public function setUp(): void
    {
        parent::setUp();
    }

    public function tearDown(): void
    {
        parent::tearDown();
    }
}

I've also php artisan config:clear and php artisan cache:clear with no luck. I did have to change the Tests name from Channel to ChannelTest not sure if that did something.

After doing all of this I'm still getting:

 • Tests\Unit\ChannelTest > a channel has many posts
   Illuminate\Contracts\Container\BindingResolutionException 

  Target class [config] does not exist.

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:877
    873▕ 
    874▕         try {
    875▕             $reflector = new ReflectionClass($concrete);
    876▕         } catch (ReflectionException $e) {
  ➜ 877▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    878▕         }
    879▕ 
    880▕         // If the type is not instantiable, the developer is attempting to resolve
    881▕         // an abstract type such as an Interface or Abstract Class and there is

      +6 vendor frames 
  7   database/factories/ChannelFactory.php:21
      fake()

      +7 vendor frames 
  15  tests/Unit/ChannelTest.php:30
      Illuminate\Database\Eloquent\Factories\Factory::create()
0 likes
3 replies
Corbin's avatar
Corbin
OP
Best Answer
Level 9

Instead of use PHPUnit\Framework\TestCase; I used use Tests\TestCase;

12 likes
inmanage's avatar

To anyone coming here from google, Check your "processIsolation" value in phpunit.xml if set to false, switch it back to true and try again.

Please or to participate in this conversation.