MiloudiMohamed's avatar

Test the Laravel socialite redirect

I've implemented Laravel socialite authentication and I'm trying to write a test to the login flow

I have the two functions: redirectToProvider and handleProviderCallback

public function redirectToProvider($provider)
{
    return Socialite::driver($provider)->redirect();
}

public function handleProviderCallback($provider)
{
   //
}

I have successfully written the test for the second method handleProviderCallback by using this gist and ajusting it for my need

what I need now is just how I call my route /login/github and redirects me to /login/github/callback

It's keep giving me **500** error

Thank you in advanced

0 likes
2 replies
bobbybouwmann's avatar

Did you look at the tests of Socialite itself? https://github.com/laravel/socialite/blob/4.0/tests/OAuthTwoTest.php

Also testing socialite isn't really a good thing, since you're testing a third party package right? The package already has tests, so there wouldn't be a need to test if the correct urls are generated. Instead you would want to test the full integration with a third-party website. That is not something you put in a unit test.

MiloudiMohamed's avatar

@BOBBYBOUWMANN - Yes i saw that before posting here

I'm not testing the socialite package itself I'm testing the redirect flow from the first function call to the second one

As far as i know I assume i should get a RedirectResponse when i hit redirectToProvider and then I can easily get the redirect url but I didn't get that, that's what confuse me

Please or to participate in this conversation.