Redirect test passes when run on it's own but fails when run after other tests

Posted 1 year ago by longestdrive

I'm trying to do a simple test to check that a user is redirected if not logged in.

When I run the test on i'ts own it passes but if I run it as part of a series of tests on a feature it fails.

here is my test:


namespace Tests\Feature\createReservation;

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

class CreateReservationFormTest extends TestCase
    use DatabaseMigrations;

     * A basic test example.
     * @return void
    public function test_user_can_see_greenfee_form()
        $user = factory(\App\Models\User::class)->create();

        $response = $this->actingAs($user)


    public function test_not_logged_in_user_is_redirected()

        $response = $this->get('bookings/create');


My route is protected by the basic auth middleware and works as expected when using the app as normal:

Route::group(array('middleware'=>['auth']), function () {

    Route::resource('bookings', 'Booking\BookingController');


When I inspect $response I can see the header has:

<!DOCTYPE html><!--

InvalidArgumentException: Route [bookings.create] not defined. in file /home/vagrant/code/golfmanager18/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 305

What do I test for. TestCase.php has not been changed

I don't know where to start solving this - any ideas?

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

Reply to

Use Markdown with GitHub-flavored code blocks.