-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathClientTest.php
More file actions
61 lines (46 loc) · 1.8 KB
/
ClientTest.php
File metadata and controls
61 lines (46 loc) · 1.8 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
<?php
namespace Tests\Vertex;
use Anthropic\Vertex\Client;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class ClientTest extends TestCase
{
/**
* @dataProvider locationBaseUrlProvider
*/
public function testBaseUrlForLocation(string $location, string $expectedHost): void
{
$client = $this->createClientWithLocation($location);
$reflection = new \ReflectionMethod($client, 'getBaseUrl');
$baseUrl = $reflection->invoke($client);
$this->assertInstanceOf(\Psr\Http\Message\UriInterface::class, $baseUrl);
$this->assertSame($expectedHost, (string) $baseUrl);
}
/**
* @return iterable<string, array{string, string}>
*/
public static function locationBaseUrlProvider(): iterable
{
yield 'global region' => ['global', 'https://aiplatform.googleapis.com'];
yield 'us region' => ['us', 'https://aiplatform.us.rep.googleapis.com'];
yield 'us-central1 region' => ['us-central1', 'https://us-central1-aiplatform.googleapis.com'];
yield 'europe-west1 region' => ['europe-west1', 'https://europe-west1-aiplatform.googleapis.com'];
yield 'asia-southeast1 region' => ['asia-southeast1', 'https://asia-southeast1-aiplatform.googleapis.com'];
}
private function createClientWithLocation(string $location): Client
{
$reflection = new \ReflectionClass(Client::class);
$constructor = $reflection->getConstructor();
assert(null !== $constructor);
$client = $reflection->newInstanceWithoutConstructor();
$credentialsProvider = function () {
throw new \RuntimeException('Should not be called in tests');
};
$constructor->invoke($client, $credentialsProvider, $location, 'test-project');
return $client;
}
}