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

tenzan's avatar

Test passing green without Controller in place

Here's the full source https://github.com/tenzan/ticketbeast

ViewConcertListingTest.php:

<?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()
    {
        // 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.');
    }
}

web.php:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/concerts/{id}', 'ConcertController@show');

I can't understand how sail test is passing green, where I don't have ConcertController created.

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true

   PASS  Tests\Feature\ViewConcertListingTest
  ✓ user can view a concert listing

  Tests:  2 passed
  Time:   2.61s
0 likes
6 replies
MohamedTammam's avatar

Are you sure that you ran your tests after saving the files?

Tray2's avatar
Tray2
Best Answer
Level 73

@tenzan All you need to to is put the following line in the beginning of your tests.

$this->withoutExceptionHandling();

Like so

/** @test */
    function user_can_view_a_concert_listing()
    {
		$this->withoutExceptionHandling(); //This line.
        // 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.');
    }
1 like
Tray2's avatar

@tenzan I think it's because of how Ignition renders the error pages, so you get false passes.

1 like

Please or to participate in this conversation.