-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(google provider): add test for GoogleProvider's getUserByToken m…
…ethod last change
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Laravel\Socialite\Tests; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\RequestOptions; | ||
use Illuminate\Http\Request; | ||
use Laravel\Socialite\Tests\Fixtures\GoogleTestProviderStub; | ||
use Laravel\Socialite\Two\User; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
class GoogleProviderTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
m::close(); | ||
} | ||
|
||
public function test_it_can_map_a_user_from_an_access_token() | ||
{ | ||
$request = Request::create('/'); | ||
|
||
$provider = new GoogleTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); | ||
|
||
$provider->http = m::mock(Client::class); | ||
|
||
$provider->http->allows('get')->with('https://www.googleapis.com/oauth2/v3/userinfo', [ | ||
RequestOptions::QUERY => [ | ||
'prettyPrint' => 'false', | ||
], | ||
RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer fake-token', | ||
], | ||
])->andReturns($response = m::mock(ResponseInterface::class)); | ||
|
||
$response->allows('getBody')->andReturns(m::mock(StreamInterface::class)); | ||
|
||
$user = $provider->userFromToken('fake-token'); | ||
|
||
$this->assertInstanceOf(User::class, $user); | ||
} | ||
} |