Jamesst20
9 months ago

Laravel 5.7 : Unable to test Patch/Put/Delete routes

Posted 9 months ago by Jamesst20

Hi,

I currently have this in my routes/web.php :

Route::middleware(['auth'])->group(function () {
    Route::resource('timesheets', 'TimesheetController');
    /* ... */
});
Auth::routes();

and have the following feature test :

    function test_guests_cant_access_actions()
    {
        $timesheet = factory(Timesheet::class)->make();

        $this->get(route('timesheets.index'))
            ->assertRedirect('/login');
        $this->get(route('timesheets.create'))
            ->assertRedirect('/login');
        $this->post(route('timesheets.store'))
            ->assertRedirect('/login');
        $this->patch(route('timesheets.update', [$timesheet]))
            ->assertRedirect('/login'); // Line 29
        $this->delete(route('timesheets.destroy', [$timesheet]))
            ->assertRedirect('/login');
    }

Sadly, I am getting this error

1) Tests\Feature\Controllers\TimesheetControllerTest::test_guests_cant_access_actions
Response status code [405] is not a redirect status code.
Failed asserting that false is true.

/home/james/Projects/workschedule/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:148
/home/james/Projects/workschedule/tests/Feature/Controllers/TimesheetControllerTest.php:29

Which means the route is not responding to my request method.

I am unable to explain it. Would anyone be able to help me understand what i'm doing wrong ?

Thank you

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