Ad
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);
$provider->expects($this->any())
->method('user')
->willReturn($socialiteUser);
// create a mock Socialite instance
$stub = $this->createMock(Socialite::class);
$stub->expects($this->any())
->method('driver')
//->with('google')
->willReturn($provider);
// 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.
Ad
Answer
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;
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad