Trying To Mock Laravel Socialite Google Login For Integration Testing

I am trying to mock Laravel Socialite to test Google oAUTH Login using the guide here.

use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GoogleProvider;
use Laravel\Socialite\Two\User as SocialUser;

public function mock_socialite ($email = '[email protected]', $token = 'foo', $id = 1)
        // create a mock user
        $socialiteUser = $this->createMock(SocialUser::class);
        $socialiteUser->token = $token;
        $socialiteUser->id = $id;
        $socialiteUser->email = $email;

        // create a mock provider of the user
        $provider = $this->createMock(GoogleProvider::class);

        // create a mock Socialite instance
        $stub = $this->createMock(Socialite::class);

        // Replace Socialite Instance with our mock
        $this->app->instance(Socialite::class, $stub);

However, I am getting the below error:

Trying to configure method "driver" which cannot be configured 
because it does not exist, has not been specified, is final, or is static

I checked and found that driver() method does exist in Illuminate\Support\Manager (from where Socialite is extended) and this method is a public method. Not sure why am I getting this error.



Socialite is a facade and often their integration is far away from how you would use it, therefor it does not have the driver method. You are including that facade to mock it, this is not the approach he has in the guide. So replacing the facade with the use statement he uses, would probably solved your problems.

use Laravel\Socialite\Contracts\Factory as Socialite;

Instead of.

use Laravel\Socialite\Facades\Socialite;