shadrix
136
1
Testing

Ignores my middleware in controller, why?

Posted 1 year ago by shadrix

I don't get it. Php unit is just ignoring my middleware in my controller. My code is simple:

public function __construct()
{
    $this->middleware(function ($request, $next) {
        if(auth()->check() && auth()->user()->confirmed){
            return redirect()->route('home');
        }

        return $next($request);
    });
    
}

When I check with:

 dd('test');
 $this->middleware...

I can see the output 'test'. But when I put it inside the middleware I cannot see. He is my test:

 /** @test */
 public function a_confirmed_auth_user_cannot_see_the_resend_page(){

    $this->signIn();

    $this->get(route('resend.confirm'))->assertRedirect(route('home'));
 }

It fails because it goes straight to my index() of route('resend.confirm'). I can't explain it :(

p.S. if I test it with the Browser, everything works fine.

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

Reply to

Use Markdown with GitHub-flavored code blocks.