Skip to content

Commit 695f589

Browse files
brendtinnocenzi
andauthored
test(auth): cover instantiating GenericOAuthClient (#1590)
Co-authored-by: Enzo Innocenzi <[email protected]>
1 parent 07d810b commit 695f589

File tree

3 files changed

+38
-50
lines changed

3 files changed

+38
-50
lines changed

packages/auth/src/OAuth/OAuthClientInitializer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace Tempest\Auth\OAuth;
66

7+
use Tempest\Auth\Authentication\Authenticator;
78
use Tempest\Auth\Exceptions\OAuthProviderWasMissing;
89
use Tempest\Auth\Exceptions\OAuthWasNotConfigured;
910
use Tempest\Container\Container;
1011
use Tempest\Container\DynamicInitializer;
1112
use Tempest\Container\Singleton;
13+
use Tempest\Http\Session\Session;
1214
use Tempest\Mapper\ObjectFactory;
1315
use Tempest\Reflection\ClassReflector;
1416
use Tempest\Router\UriGenerator;
@@ -38,6 +40,8 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con
3840
config: $config,
3941
uri: $container->get(UriGenerator::class),
4042
factory: $container->get(ObjectFactory::class),
43+
session: $container->get(Session::class),
44+
authenticator: $container->get(Authenticator::class),
4145
);
4246
}
4347
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Tests\Tempest\Integration\Auth\OAuth;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Tempest\Auth\Exceptions\OAuthWasNotConfigured;
7+
use Tempest\Auth\OAuth\Config\GitHubOAuthConfig;
8+
use Tempest\Auth\OAuth\GenericOAuthClient;
9+
use Tempest\Auth\OAuth\OAuthClient;
10+
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
11+
12+
final class GenericOAuthClientTest extends FrameworkIntegrationTestCase
13+
{
14+
#[Test]
15+
public function creates_oauth_client(): void
16+
{
17+
$this->container->config(new GitHubOAuthConfig(
18+
clientId: 'client-id',
19+
clientSecret: 'client-secret', // @mago-expect lint:no-literal-password
20+
redirectTo: '/oauth/callback',
21+
scopes: ['user:email'],
22+
));
23+
24+
$this->assertInstanceOf(GenericOAuthClient::class, $this->container->get(OAuthClient::class));
25+
}
26+
27+
#[Test]
28+
public function throws_when_no_config(): void
29+
{
30+
$this->expectException(OAuthWasNotConfigured::class);
31+
32+
$this->container->get(OAuthClient::class);
33+
}
34+
}

tests/Integration/Auth/OAuth/OAuthClientTest.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)