nicejjss's avatar

Laravel testing

I have an api that not use authentication of laravel but I use custom guard

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
 
/**
 * Register any application authentication / authorization services.
 */
public function boot(): void
{
    Auth::viaRequest('custom-token', function (Request $request) {
        return User::where('token', (string) $request->token)->first();
    });
}

How can I use Laravel testing to test my api, I have tried withHeader with Authentication but it not works

0 likes
2 replies
tykus's avatar

Your authentication token is in the query string, right, so the Request header does not make sense in your test. It should be sufficient to make the test request with a valid token in the query string.

1 like
nicejjss's avatar

@tykus So what you mean is I must know how the authentication work in my app so that I can create the test right?

Please or to participate in this conversation.