Testing socialite Hi,
I am using socialite for linked in login and I am trying to right some functional tests to check the controller login flow but I am having trouble mocking out the socialite library.
Has anyone done this? Do I need to mock the whole thing by hand or is the a quick way?
Thanks
It looks like the basic socialite facade can be mocked using Laravel's default mocking ability but once you get past that I am not sure how to correctly mock the response.
\Socialite::shouldReceive('driver')->once()->with('linkedin')->andReturn(\Socialite::shouldReceive('user')->once());
This successfully mocks the following line of code
$linkedInUser = Socialite::driver('linkedin')->user();
What I need to do now is return a mock user object that matches the Laravel\Socialite\AbstractUser class, so far I haven't gotten this to work.
It's slightly annoying that this package was made available with no guidance on how to test it.
@ArthurGuy
I would love to know if you now have a solution for this. kindly share if you have.
Thanks
To help anyone who follow the same research path as i did, here is a good way to mock Socialite callback :
$abstractUser = Mockery::mock('Laravel\Socialite\Two\User');
$abstractUser->shouldReceive('getId')
->andReturn(1234567890)
->shouldReceive('getEmail')
->andReturn(str_random(10).'@test.com ')
->shouldReceive('getNickname')
->andReturn('Pseudo')
->shouldReceive('getName')
->andReturn('Arlette Laguiller')
->shouldReceive('getAvatar')
->andReturn('https://en.gravatar.com/userimage');
$provider = Mockery::mock('Laravel\Socialite\Contracts\Provider');
$provider->shouldReceive('user')->andReturn($abstractUser);
Socialite::shouldReceive('driver')->with('facebook')->andReturn($provider);
$this->visit(route("authFacebookCallback"))
->seePageIs(route("home"));
Answer found here :
http://stackoverflow.com/questions/35294257/how-to-test-laravel-socialite
Thank you @supad this is exactly what I was looking for!
Please sign in or create an account to participate in this conversation.