D
D
Div-Man2018-12-25 15:30:06
Laravel
Div-Man, 2018-12-25 15:30:06

How to make a test for middleware?

You can open the /create page only for those who are logged in

Route::get('/create', '[email protected]')->middleware('user');

I'm doing such a test, but it will only work if you remove the intermediary from the route
public function testCreateImgTest()
        {
            $response = $this->get('/create');
    
            $response->assertStatus(200);
        }

I don't know how to do it for middleware.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-12-25
@Div-Man

public function testCreateImgTest()
{
    $this->actingAs($someExistingUser);

    $this->get('/create')->assertOk();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question