|
| 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