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

tenzan's avatar

Target class [ConcertsController] does not exist.

Hi, Full source code here https://github.com/tenzan/ticketbeast.

Although, I have ConcertsController available :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ConcertsController extends Controller {}

Testing ViewConcertListingTest :

<?php

namespace Tests\Feature;

// use Illuminate\Foundation\Testing\RefreshDatabase;

use App\Models\Concert;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ViewConcertListingTest extends TestCase
{
    use DatabaseMigrations;

    /** @test */
    function user_can_view_a_concert_listing()
    {
        $this->withoutExceptionHandling();

        // Arrange
        // Create a concert
        $concert = Concert::create([
            'title' => 'Sample Title',
            'subtitle' => 'Sample Subtitle',
            'date' => Carbon::parse('December 13, 2016 8:00pm'),
            'ticket_price' => 3250,
            'venue' => 'Sample Venue',
            'venue_address' => '123 Sample Address',
            'city' => 'Some City',
            'state' => 'ON',
            'zip' => '12345',
            'additional_information' => 'For tickets, call (555) 555-5555.'
        ]);

        // Act
        // View the concert listing
        $view = $this->get('/concerts/'.$concert->id);

        // Assert
        // see the concert details
        $view->assertSee('Sample Title');
        $view->assertSee('Sample Subtitle');
        $view->assertSee('December 13, 2016');
        $view->assertSee('8:00pm');
        $view->assertSee('32.50');
        $view->assertSee('Sample Venue',);
        $view->assertSee('123 Sample Address');
        $view->assertSee('Some City, ON 12345');
        $view->assertSee('For tickets, call (555) 555-5555.');
    }
}

giving an error:

   FAIL  Tests\Feature\ViewConcertListingTest
  ⨯ user can view a concert listing

  ---

  • Tests\Feature\ViewConcertListingTest > user can view a concert listing
   Illuminate\Contracts\Container\BindingResolutionException 

  Target class [ConcertsController] 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

      +33 vendor frames 
  34  tests/Feature/ViewConcertListingTest.php:38
      Illuminate\Foundation\Testing\TestCase::get()


  Tests:  1 failed, 1 passed
  Time:   1.89s
0 likes
6 replies
MohamedTammam's avatar

@tenzan How it was before was correct for older versions, From Laravel 9 what I posted is the new way for passing controllers and methods to the route.

tenzan's avatar

@MohamedTammam Indeed I was referring to the information on testing based on old laravel. So I was trying to find out the new way. Thanks again for your help!

1 like

Please or to participate in this conversation.