Skip to content

Commit

Permalink
feat(google provider): add test for GoogleProvider's getUserByToken m…
Browse files Browse the repository at this point in the history
…ethod last change
  • Loading branch information
alibori committed Feb 10, 2024
1 parent 1e0324a commit fa0fc7e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/GoogleProviderTest.php
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);
}
}

0 comments on commit fa0fc7e

Please sign in to comment.