Skip to content

Instantly share code, notes, and snippets.

@jlmaners
Last active January 1, 2024 21:15
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jlmaners/eb5f9f7bf6ca7f6c3ec02270d9959876 to your computer and use it in GitHub Desktop.
Save jlmaners/eb5f9f7bf6ca7f6c3ec02270d9959876 to your computer and use it in GitHub Desktop.
Mocking Socialite
<?php
$mockSocialite = \Mockery::mock('Laravel\Socialite\Contracts\Factory');
$this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
$abstractUser = Mockery::mock('Laravel\Socialite\Two\User');
$abstractUser
->shouldReceive('getId')
->andReturn(rand())
->shouldReceive('getName')
->andReturn(str_random(10))
->shouldReceive('getEmail')
->andReturn($username.'@ncsu.edu')
->shouldReceive('getAvatar')
->andReturn('https://en.gravatar.com/userimage');
$provider = Mockery::mock('Laravel\Socialite\Contract\Provider');
$provider->shouldReceive('user')->andReturn($abstractUser);
$mockSocialite->shouldReceive('driver')->andReturn($provider);
$response = $this->get('/login/google/callback');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment