EndpointTraitTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Regions;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\AlibabaCloud;
  5. use AlibabaCloud\Client\Request\RpcRequest;
  6. use AlibabaCloud\Client\Regions\LocationService;
  7. use AlibabaCloud\Client\Exception\ServerException;
  8. use AlibabaCloud\Client\Exception\ClientException;
  9. /**
  10. * Class EndpointTraitTest
  11. *
  12. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Regions
  13. */
  14. class EndpointTraitTest extends TestCase
  15. {
  16. /**
  17. * @return array
  18. */
  19. public function products()
  20. {
  21. return [
  22. [
  23. 'Slb',
  24. 'slb',
  25. [
  26. 'slb.aliyuncs.com',
  27. '',
  28. ],
  29. ],
  30. [
  31. 'Ess',
  32. 'ess',
  33. [
  34. 'ess.aliyuncs.com',
  35. '',
  36. ],
  37. ],
  38. [
  39. 'EHPC',
  40. 'ehs',
  41. [
  42. 'ehpc.cn-hangzhou.aliyuncs.com',
  43. '',
  44. ],
  45. ],
  46. [
  47. 'EHPC',
  48. 'badServiceCode',
  49. [
  50. 'ehpc.cn-hangzhou.aliyuncs.com',
  51. '',
  52. ],
  53. ],
  54. [
  55. 'Slb',
  56. '',
  57. [
  58. 'slb.aliyuncs.com',
  59. '',
  60. ],
  61. ],
  62. ];
  63. }
  64. /**
  65. * @dataProvider products
  66. *
  67. * @param string $productName
  68. * @param string $serviceCode
  69. * @param array $expectedHost
  70. *
  71. * @throws ClientException
  72. * @throws ServerException
  73. */
  74. public function testLocationServiceResolveHost($productName, $serviceCode, array $expectedHost)
  75. {
  76. // Setup
  77. $accessKeyId = \getenv('ACCESS_KEY_ID');
  78. $accessKeySecret = \getenv('ACCESS_KEY_SECRET');
  79. AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
  80. ->regionId('cn-hangzhou')
  81. ->asDefaultClient();
  82. // Test
  83. $request = new RpcRequest();
  84. $request->connectTimeout(25)->timeout(30);
  85. $request->product = $productName;
  86. $request->serviceCode = $serviceCode;
  87. // Assert
  88. $host = LocationService::resolveHost($request);
  89. self::assertContains($host, $expectedHost);
  90. }
  91. }