-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathOAuthInstallerTest.php
More file actions
133 lines (122 loc) · 5.6 KB
/
OAuthInstallerTest.php
File metadata and controls
133 lines (122 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
declare(strict_types=1);
namespace Tests\Tempest\Integration\Auth\Installer;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Tempest\Auth\OAuth\SupportedOAuthProvider;
use Tempest\Support\Namespace\Psr4Namespace;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
final class OAuthInstallerTest extends FrameworkIntegrationTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->installer
->configure(
__DIR__ . '/install',
new Psr4Namespace('App\\', __DIR__ . '/install/App'),
)
->setRoot(__DIR__ . '/install')
->put('.env.example', '')
->put('.env', '');
}
protected function tearDown(): void
{
$this->installer->clean();
parent::tearDown();
}
#[Test]
#[DataProvider('oauthProvider')]
public function install_oauth_provider(
SupportedOAuthProvider $provider,
string $expectedConfigPath,
string $expectedControllerPath,
): void {
$this->console
->call('install auth --oauth')
->confirm() // Running the installer, continue?
->deny() // Publish CreateUsersTable?
->deny() // Publish User?
->deny() // Publish MustBeAuthenticated?
->deny() // Publish AuthenticateUserController?
->input($provider->value) // Pick provider
->confirm() // Confirm provider
->confirm() // Publish $ProviderController
->confirm() // Publish $provider.config.php
->confirm() // Add to .env
->confirm() // Install dependencies
->assertSee('The selected OAuth provider is installed in your project')
->assertSuccess();
$this->installer
->assertFileExists($expectedConfigPath)
->assertFileContains($expectedConfigPath, $provider::class)
->assertFileExists($expectedControllerPath)
->assertFileContains($expectedControllerPath, $provider::class)
->assertFileContains('.env', "OAUTH_{$provider->name}_CLIENT_ID")
->assertFileContains('.env.example', "OAUTH_{$provider->name}_CLIENT_ID");
$composerPackage = $provider->composerPackage();
if ($composerPackage !== null) {
$this->installer->assertCommandExecuted("composer require {$provider->composerPackage()}");
}
}
public static function oauthProvider(): array
{
return [
'apple' => [
'provider' => SupportedOAuthProvider::APPLE,
'expectedConfigPath' => 'App/Authentication/OAuth/apple.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/AppleController.php',
],
'discord' => [
'provider' => SupportedOAuthProvider::DISCORD,
'expectedConfigPath' => 'App/Authentication/OAuth/discord.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/DiscordController.php',
],
'facebook' => [
'provider' => SupportedOAuthProvider::FACEBOOK,
'expectedConfigPath' => 'App/Authentication/OAuth/facebook.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/FacebookController.php',
],
'generic' => [
'provider' => SupportedOAuthProvider::GENERIC,
'expectedConfigPath' => 'App/Authentication/OAuth/generic.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/GenericController.php',
],
'github' => [
'provider' => SupportedOAuthProvider::GITHUB,
'expectedConfigPath' => 'App/Authentication/OAuth/github.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/GithubController.php',
],
'google' => [
'provider' => SupportedOAuthProvider::GOOGLE,
'expectedConfigPath' => 'App/Authentication/OAuth/google.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/GoogleController.php',
],
'instagram' => [
'provider' => SupportedOAuthProvider::INSTAGRAM,
'expectedConfigPath' => 'App/Authentication/OAuth/instagram.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/InstagramController.php',
],
'linkedin' => [
'provider' => SupportedOAuthProvider::LINKEDIN,
'expectedConfigPath' => 'App/Authentication/OAuth/linkedin.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/LinkedInController.php',
],
'microsoft' => [
'provider' => SupportedOAuthProvider::MICROSOFT,
'expectedConfigPath' => 'App/Authentication/OAuth/microsoft.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/MicrosoftController.php',
],
'slack' => [
'provider' => SupportedOAuthProvider::SLACK,
'expectedConfigPath' => 'App/Authentication/OAuth/slack.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/SlackController.php',
],
'twitch' => [
'provider' => SupportedOAuthProvider::TWITCH,
'expectedConfigPath' => 'App/Authentication/OAuth/twitch.config.php',
'expectedControllerPath' => 'App/Authentication/OAuth/TwitchController.php',
],
];
}
}