EndpointTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace AlibabaCloud\Endpoint\Tests;
  3. use AlibabaCloud\Endpoint\Endpoint;
  4. use PHPUnit\Framework\TestCase;
  5. /**
  6. * @internal
  7. * @coversNothing
  8. */
  9. class EndpointTest extends TestCase
  10. {
  11. public function testGetEndpointWhenInvalidProduct()
  12. {
  13. $this->expectException(\InvalidArgumentException::class);
  14. $this->expectExceptionMessage('Product name cannot be empty.');
  15. Endpoint::getEndpointRules('', '', '', '');
  16. }
  17. public function testGetEndpointWhenInvalidEndpointType()
  18. {
  19. $this->expectException(\InvalidArgumentException::class);
  20. $this->expectExceptionMessage('Invalid EndpointType');
  21. Endpoint::getEndpointRules('ecs', '', 'fake endpoint type', '');
  22. }
  23. public function testGetEndpointWhenInvalidRegionId()
  24. {
  25. $this->expectException(\InvalidArgumentException::class);
  26. $this->expectExceptionMessage('RegionId is empty, please set a valid RegionId');
  27. Endpoint::getEndpointRules('ecs', '', Endpoint::ENDPOINT_TYPE_REGIONAL, '');
  28. }
  29. public function testGetEndpointCentral()
  30. {
  31. $endpoint = Endpoint::getEndpointRules('ecs', '', Endpoint::ENDPOINT_TYPE_CENTRAL);
  32. $this->assertEquals('ecs.aliyuncs.com', $endpoint);
  33. }
  34. public function testGetEndpointRegional()
  35. {
  36. $endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL);
  37. $this->assertEquals('ecs.cn-hangzhou.aliyuncs.com', $endpoint);
  38. }
  39. public function testGetEndpointRegionalWithNetwork()
  40. {
  41. $endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL, 'internal');
  42. $this->assertEquals('ecs-internal.cn-hangzhou.aliyuncs.com', $endpoint);
  43. }
  44. public function testGetEndpointRegionalWithSuffix()
  45. {
  46. $endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL, 'internal', 'test');
  47. $this->assertEquals('ecs-test-internal.cn-hangzhou.aliyuncs.com', $endpoint);
  48. }
  49. }