[英]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.