James Okpe George James Okpe George - 1 year ago 121
PHP Question

How to Test Laravel Socialite

I have an application that makes use of socialite, I want to create test for Github authentication, So I used Socialite Facade to mock call to the Socialite

method, but when I run my test it tells me that I am trying to get value on null type.

Below is the test I have written

public function testGithubLogin()
$this->call('GET', '/github/authorize')->isRedirection();

Below is the implementation of the test

public function authorizeProvider($provider)
return Socialite::driver($provider)->redirect();

I understand why it might return such result because
returns an instance of
, and considering that I am unable to instantiate this value it will be impossible to specify a return type. I need help to successfully test the controller. Thanks

Answer Source

Well, both answers were great, but they have lots of codes that are not required, and I was able to infer my answer from them.

This is all I needed to do.

Firstly mock the Socialite User type

$abstractUser = Mockery::mock('Laravel\Socialite\Two\User')

Second, set the expected values for its method calls

   ->andReturn(str_random(10) . '@gmail.com')

Then lastly you write your assertions

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download