|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace AsyncAws\Core\Tests\Unit; |
| 6 | + |
| 7 | +use AsyncAws\Core\AbstractApi; |
| 8 | +use AsyncAws\Core\Configuration; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class AbstractApiTest extends TestCase |
| 12 | +{ |
| 13 | + public function testGetEndpointRegion() |
| 14 | + { |
| 15 | + $api = new DummyApi(); |
| 16 | + |
| 17 | + // Use default region |
| 18 | + $endpoint = $api->getEndpoint('/some/path', [], null); |
| 19 | + self::assertEquals('https://foobar.us-east-1.amazonaws.com/some/path', $endpoint); |
| 20 | + |
| 21 | + $endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1'); |
| 22 | + self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint); |
| 23 | + |
| 24 | + // Use region from config |
| 25 | + $api = new DummyApi(['region' => 'eu-north-1']); |
| 26 | + $endpoint = $api->getEndpoint('/some/path', [], null); |
| 27 | + self::assertEquals('https://foobar.eu-north-1.amazonaws.com/some/path', $endpoint); |
| 28 | + |
| 29 | + $endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1'); |
| 30 | + self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +class DummyApi extends AbstractApi |
| 35 | +{ |
| 36 | + public function getEndpoint(string $uri, array $query, ?string $region): string |
| 37 | + { |
| 38 | + return parent::getEndpoint($uri, $query, $region); |
| 39 | + } |
| 40 | + |
| 41 | + protected function getEndpointMetadata(?string $region): array |
| 42 | + { |
| 43 | + if (null === $region) { |
| 44 | + $region = Configuration::DEFAULT_REGION; |
| 45 | + } |
| 46 | + |
| 47 | + return [ |
| 48 | + 'endpoint' => "https://foobar.$region.amazonaws.com", |
| 49 | + 'signRegion' => $region, |
| 50 | + 'signService' => 'foobar', |
| 51 | + 'signVersions' => ['v4'], |
| 52 | + ]; |
| 53 | + } |
| 54 | +} |
0 commit comments