Skip to content

Commit cd26540

Browse files
committed
test(auth): add OAuthInstaller integration test
1 parent 6ace392 commit cd26540

File tree

2 files changed

+132
-5
lines changed

2 files changed

+132
-5
lines changed

packages/auth/src/Installer/OAuthInstaller.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Tempest\Auth\Installer;
66

7-
use Symfony\Component\Process\Process;
87
use Tempest\Auth\OAuth\SupportedOAuthProvider;
98
use Tempest\Core\PublishesFiles;
9+
use Tempest\Process\ProcessExecutor;
1010
use Tempest\Support\Filesystem\Exceptions\PathWasNotFound;
1111
use Tempest\Support\Filesystem\Exceptions\PathWasNotReadable;
1212
use Tempest\Support\Str\ImmutableString;
@@ -22,6 +22,10 @@ final class OAuthInstaller
2222
{
2323
use PublishesFiles;
2424

25+
public function __construct(
26+
private readonly ProcessExecutor $processExecutor,
27+
) {}
28+
2529
public function install(): void
2630
{
2731
$providers = $this->getProviders();
@@ -133,10 +137,7 @@ private function installComposerDependencies(SupportedOAuthProvider ...$provider
133137
->filter();
134138

135139
if ($packages->isNotEmpty()) {
136-
$this->task(
137-
label: "Installing composer dependencies {$packages->implode(', ')}",
138-
handler: new Process(['composer', 'require', ...$packages], cwd: root_path()),
139-
);
140+
$this->processExecutor->run("composer require {$packages->implode(', ')}");
140141
}
141142
}
142143

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

0 commit comments

Comments
 (0)