[英]Trying to mock Laravel Socialite Google Login for integration testing
我正在尝试使用此处的指南模拟Laravel Socialite以测试Google oAUTH登录。
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\GoogleProvider;
use Laravel\Socialite\Two\User as SocialUser;
public function mock_socialite ($email = 'foo@gmail.com', $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);
}
但是,我收到以下错误:
Trying to configure method "driver" which cannot be configured
because it does not exist, has not been specified, is final, or is static
我检查发现, Illuminate\\Support\\Manager
( Socialite
的扩展位置)中确实存在driver()
方法,并且该方法是公共方法。 不知道为什么会收到此错误。
社交名媛是一个门面,通常它们的集成与您的使用方式相去甚远,因此它没有驱动程序方法。 您要包括模拟该外观的外观,这不是他在指南中所采用的方法。 因此,用他使用的use语句替换外观,可能会解决您的问题。
use Laravel\Socialite\Contracts\Factory as Socialite;
代替。
use Laravel\Socialite\Facades\Socialite;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.