PHP code example of cndrsdrmn / socialite

1. Go to this page and download the library: Download cndrsdrmn/socialite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cndrsdrmn / socialite example snippets


use Laravel\Socialite\Facades\Socialite;

it('fakes socialite and tracks redirects', function () {
    Socialite::fake();

    // Assert that no redirect has happened yet.
    Socialite::assertNotRedirected();

    // Trigger a redirect using the default fake driver.
    $response = Socialite::driver('default')->redirect();

    // Assert that a redirect was correctly tracked.
    Socialite::assertRedirected();

    expect($response->getStatusCode())->toBe(302);
    expect($response->headers->get('X-Socialite-Fake'))->toBe('1');
});

use Laravel\Socialite\Facades\Socialite;

it('returns a fake user with configured attributes', function () {
    Socialite::fake([
        'github' => [
            'id' => 'user-1',
            'name' => 'John Doe',
            'email' => '[email protected]',
            'nickname' => 'john.doe',
            'avatar' => 'https://example.com/john.jpg',
        ],
    ]);

    $user = Socialite::driver('github')->user();

    // Use the built-in assertions to verify the user data.
    Socialite::assertUser([
        'id' => 'user-1',
        'name' => 'John Doe',
        'email' => '[email protected]',
        'nickname' => 'john.doe',
        'avatar' => 'https://example.com/john.jpg',
    ]);

    // You can also assert directly on the returned user object.
    expect($user->getId())->toBe('user-1');
});

[
    'id' => 'uuid-v4',
    'name' => 'Fake User',
    'email' => '[email protected]',
    'nickname' => 'fake',
    'avatar' => 'https://example.com/avatar.jpg',
]

use Exception;
use Laravel\Socialite\Facades\Socialite;

Socialite::fake(withFailure: new Exception('Boom'));

// The following line will now throw the configured exception.
expect(fn () => Socialite::driver('github')->user())
    ->toThrow(Exception::class);