|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Vertex; |
| 4 | + |
| 5 | +use Anthropic\Vertex\Client; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * @internal |
| 10 | + * |
| 11 | + * @coversNothing |
| 12 | + */ |
| 13 | +class ClientTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider locationBaseUrlProvider |
| 17 | + */ |
| 18 | + public function testBaseUrlForLocation(string $location, string $expectedHost): void |
| 19 | + { |
| 20 | + $client = $this->createClientWithLocation($location); |
| 21 | + |
| 22 | + $reflection = new \ReflectionMethod($client, 'getBaseUrl'); |
| 23 | + $baseUrl = $reflection->invoke($client); |
| 24 | + |
| 25 | + $this->assertInstanceOf(\Psr\Http\Message\UriInterface::class, $baseUrl); |
| 26 | + $this->assertSame($expectedHost, (string) $baseUrl); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @return iterable<string, array{string, string}> |
| 31 | + */ |
| 32 | + public static function locationBaseUrlProvider(): iterable |
| 33 | + { |
| 34 | + yield 'global region' => ['global', 'https://aiplatform.googleapis.com']; |
| 35 | + |
| 36 | + yield 'us region' => ['us', 'https://aiplatform.us.rep.googleapis.com']; |
| 37 | + |
| 38 | + yield 'us-central1 region' => ['us-central1', 'https://us-central1-aiplatform.googleapis.com']; |
| 39 | + |
| 40 | + yield 'europe-west1 region' => ['europe-west1', 'https://europe-west1-aiplatform.googleapis.com']; |
| 41 | + |
| 42 | + yield 'asia-southeast1 region' => ['asia-southeast1', 'https://asia-southeast1-aiplatform.googleapis.com']; |
| 43 | + } |
| 44 | + |
| 45 | + private function createClientWithLocation(string $location): Client |
| 46 | + { |
| 47 | + $reflection = new \ReflectionClass(Client::class); |
| 48 | + $constructor = $reflection->getConstructor(); |
| 49 | + assert(null !== $constructor); |
| 50 | + |
| 51 | + $client = $reflection->newInstanceWithoutConstructor(); |
| 52 | + |
| 53 | + $credentialsProvider = function () { |
| 54 | + throw new \RuntimeException('Should not be called in tests'); |
| 55 | + }; |
| 56 | + |
| 57 | + $constructor->invoke($client, $credentialsProvider, $location, 'test-project'); |
| 58 | + |
| 59 | + return $client; |
| 60 | + } |
| 61 | +} |
0 commit comments