Skip to content

Commit 9299928

Browse files
authored
Test gitlab and dropbox driver instantiation. (#2)
Fix default Gitlab driver being tested instead of Socialite Providers one. Add test for Dropbox driver.
1 parent c8993c9 commit 9299928

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

tests/TestCase.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Laravel\Socialite\SocialiteServiceProvider;
99
use Orchestra\Testbench\TestCase as BaseTestCase;
1010
use Oneofftech\Identities\Providers\IdentitiesServiceProvider;
11+
use SocialiteProviders\Dropbox\DropboxExtendSocialite;
12+
use SocialiteProviders\GitLab\GitLabExtendSocialite;
13+
use SocialiteProviders\Manager\SocialiteWasCalled;
1114

1215
abstract class TestCase extends BaseTestCase
1316
{
@@ -19,7 +22,7 @@ public function setUp(): void
1922
{
2023
parent::setUp();
2124

22-
// Your code here
25+
$this->activateSocialiteExtensions();
2326
}
2427

2528
/**
@@ -45,6 +48,11 @@ protected function getEnvironmentSetUp($app)
4548
'redirect' => null,
4649
'instance_uri' => 'https://gitlab.com/'
4750
]);
51+
$app['config']->set('services.dropbox', [
52+
'client_id' => 'aaa',
53+
'client_secret' => 'bbb',
54+
'redirect' => null,
55+
]);
4856

4957
$key = Str::random(32);
5058
$app['config']->set('app.key', $key);
@@ -64,6 +72,14 @@ protected function getPackageProviders($app)
6472
];
6573
}
6674

75+
protected function activateSocialiteExtensions()
76+
{
77+
$socialiteWasCalled = $this->app->make(SocialiteWasCalled::class);
78+
79+
$this->app->make(GitLabExtendSocialite::class)->handle($socialiteWasCalled);
80+
$this->app->make(DropboxExtendSocialite::class)->handle($socialiteWasCalled);
81+
}
82+
6783
public function assertListenerIsAttachedToEvent($listener, $event)
6884
{
6985
$dispatcher = app(Dispatcher::class);

tests/Unit/IdentityServiceProviderTest.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace Tests\Unit;
44

55
use Tests\TestCase;
6-
use Laravel\Socialite\Two\GitlabProvider;
6+
use SocialiteProviders\Dropbox\Provider as DropboxDriver;
77
use Oneofftech\Identities\Facades\Identity;
88
use Oneofftech\Identities\IdentitiesManager;
99
use SocialiteProviders\Manager\SocialiteWasCalled;
1010
use SocialiteProviders\GitLab\GitLabExtendSocialite;
1111
use Illuminate\Foundation\Testing\DatabaseMigrations;
12+
use InvalidArgumentException;
13+
use Laravel\Socialite\Two\FacebookProvider;
14+
use SocialiteProviders\GitLab\Provider as GitlabSocialiteProvider;
1215

1316
class IdentityServiceProviderTest extends TestCase
1417
{
@@ -19,8 +22,41 @@ public function test_it_can_instantiate_the_gitlab_driver()
1922
$factory = $this->app->make(IdentitiesManager::class);
2023

2124
$provider = $factory->driver('gitlab');
25+
26+
$this->assertInstanceOf(GitlabSocialiteProvider::class, $provider);
27+
}
28+
29+
public function test_it_can_instantiate_the_facebook_driver()
30+
{
31+
$this->app['config']->set('services.facebook', [
32+
'client_id' => 'aaa',
33+
'client_secret' => 'bbb',
34+
'redirect' => null,
35+
]);
36+
37+
$factory = $this->app->make(IdentitiesManager::class);
38+
39+
$provider = $factory->driver('facebook');
40+
41+
$this->assertInstanceOf(FacebookProvider::class, $provider);
42+
}
43+
44+
public function test_non_existing_provider_throws()
45+
{
46+
$factory = $this->app->make(IdentitiesManager::class);
47+
48+
$this->expectException(InvalidArgumentException::class);
49+
50+
$provider = $factory->driver('slurpbook');
51+
}
52+
53+
public function test_it_can_instantiate_the_dropbox_driver()
54+
{
55+
$factory = $this->app->make(IdentitiesManager::class);
56+
57+
$provider = $factory->driver('dropbox');
2258

23-
$this->assertInstanceOf(GitlabProvider::class, $provider);
59+
$this->assertInstanceOf(DropboxDriver::class, $provider);
2460
}
2561

2662
public function test_routes_are_registered()

0 commit comments

Comments
 (0)