-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhopClientTest.php
More file actions
145 lines (121 loc) · 5.48 KB
/
WhopClientTest.php
File metadata and controls
145 lines (121 loc) · 5.48 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
134
135
136
137
138
139
140
141
142
143
144
145
<?php
declare(strict_types=1);
namespace Rapttor\WhopSdk\Tests\Unit;
use Rapttor\WhopSdk\Resources\AccessTokens;
use Rapttor\WhopSdk\Resources\Apps;
use Rapttor\WhopSdk\Resources\CheckoutConfigurations;
use Rapttor\WhopSdk\Resources\Companies;
use Rapttor\WhopSdk\Resources\Experiences;
use Rapttor\WhopSdk\Resources\Invoices;
use Rapttor\WhopSdk\Resources\Members;
use Rapttor\WhopSdk\Resources\Memberships;
use Rapttor\WhopSdk\Resources\Payments;
use Rapttor\WhopSdk\Resources\Plans;
use Rapttor\WhopSdk\Resources\Products;
use Rapttor\WhopSdk\Resources\PromoCodes;
use Rapttor\WhopSdk\Resources\Refunds;
use Rapttor\WhopSdk\Resources\Reviews;
use Rapttor\WhopSdk\Resources\Users;
use Rapttor\WhopSdk\Resources\Webhooks;
use Rapttor\WhopSdk\Tests\SdkTestCase;
use Rapttor\WhopSdk\WhopClient;
/**
* @covers \Rapttor\WhopSdk\WhopClient
*/
final class WhopClientTest extends SdkTestCase
{
// ── Construction ───────────────────────────────────────────────────────────
public function testConstructWithExplicitApiKey(): void
{
$client = new WhopClient(apiKey: 'my_key');
$this->assertInstanceOf(WhopClient::class, $client);
}
public function testConstructReadsApiKeyFromEnvironment(): void
{
putenv('WHOP_API_KEY=env_key_123');
$client = new WhopClient();
$this->assertInstanceOf(WhopClient::class, $client);
putenv('WHOP_API_KEY=');
}
public function testConstructThrowsWhenNoApiKeyProvided(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/api key/i');
putenv('WHOP_API_KEY=');
new WhopClient();
}
// ── Resource access ────────────────────────────────────────────────────────
/**
* @dataProvider resourceProvider
*/
public function testResourceAccessReturnsCorrectType(string $property, string $expectedClass): void
{
$client = $this->makeClient();
$this->assertInstanceOf($expectedClass, $client->$property);
}
/**
* @return array<string, array{string, class-string}>
*/
public static function resourceProvider(): array
{
return [
'accessTokens' => ['accessTokens', AccessTokens::class],
'apps' => ['apps', Apps::class],
'checkoutConfigurations' => ['checkoutConfigurations', CheckoutConfigurations::class],
'companies' => ['companies', Companies::class],
'experiences' => ['experiences', Experiences::class],
'invoices' => ['invoices', Invoices::class],
'members' => ['members', Members::class],
'memberships' => ['memberships', Memberships::class],
'payments' => ['payments', Payments::class],
'plans' => ['plans', Plans::class],
'products' => ['products', Products::class],
'promoCodes' => ['promoCodes', PromoCodes::class],
'refunds' => ['refunds', Refunds::class],
'reviews' => ['reviews', Reviews::class],
'users' => ['users', Users::class],
'webhooks' => ['webhooks', Webhooks::class],
];
}
public function testResourceIsCachedOnSubsequentAccess(): void
{
$client = $this->makeClient();
$first = $client->payments;
$second = $client->payments;
$this->assertSame($first, $second);
}
public function testIssetReturnsTrueForKnownResource(): void
{
$client = $this->makeClient();
$this->assertTrue(isset($client->payments));
}
public function testIssetReturnsFalseForUnknownResource(): void
{
$client = $this->makeClient();
$this->assertFalse(isset($client->unknown));
}
public function testAccessingUnknownResourceThrowsInvalidArgument(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/unknown resource/i');
$client = $this->makeClient();
/** @phpstan-ignore-next-line */
$client->doesNotExist;
}
// ── withOptions ────────────────────────────────────────────────────────────
public function testWithOptionsReturnsNewClientInstance(): void
{
$client = $this->makeClient();
$derived = $client->withOptions(['max_retries' => 0]);
$this->assertNotSame($client, $derived);
$this->assertInstanceOf(WhopClient::class, $derived);
}
public function testWithOptionsClearsCachedResources(): void
{
$client = $this->makeClient();
$before = $client->payments; // populate cache
$derived = $client->withOptions(['timeout' => 5]);
$after = $derived->payments; // new instance, fresh cache
$this->assertNotSame($before, $after);
}
}