AccessKeyCredentialTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\AlibabaCloud;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. use AlibabaCloud\Client\Tests\Mock\Services\Vpc\DescribeVpcsRequest;
  8. use AlibabaCloud\Client\Tests\Mock\Services\Dds\DescribeRegionsRequest;
  9. use AlibabaCloud\Client\Tests\Mock\Services\Cdn\DescribeCdnServiceRequest;
  10. use AlibabaCloud\Client\Tests\Mock\Services\Ecs\DescribeAccessPointsRequest;
  11. /**
  12. * Class AccessKeyCredentialTest
  13. *
  14. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials
  15. */
  16. class AccessKeyCredentialTest extends TestCase
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $clientName = 'AccessKeyCredentialTest';
  22. /**
  23. * @throws ClientException
  24. */
  25. public function setUp()
  26. {
  27. $regionId = 'cn-hangzhou';
  28. $accessKeyId = \getenv('ACCESS_KEY_ID');
  29. $accessKeySecret = \getenv('ACCESS_KEY_SECRET');
  30. AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
  31. ->regionId($regionId)
  32. ->name($this->clientName);
  33. }
  34. /**
  35. * @throws ClientException
  36. */
  37. public function tearDown()
  38. {
  39. AlibabaCloud::del($this->clientName);
  40. }
  41. /**
  42. * @throws ClientException
  43. * @throws ServerException
  44. */
  45. public function testEcs()
  46. {
  47. $result = (new DescribeAccessPointsRequest())
  48. ->client($this->clientName)
  49. ->connectTimeout(25)
  50. ->timeout(30)
  51. ->request();
  52. static::assertArrayHasKey('AccessPointSet', $result);
  53. }
  54. /**
  55. * @throws ClientException
  56. * @throws ServerException
  57. */
  58. public function testDds()
  59. {
  60. $result = (new DescribeRegionsRequest())
  61. ->client($this->clientName)
  62. ->connectTimeout(25)
  63. ->timeout(30)
  64. ->request();
  65. static::assertArrayHasKey('Regions', $result);
  66. }
  67. /**
  68. * @expectedException \AlibabaCloud\Client\Exception\ServerException
  69. * @expectedExceptionMessageRegExp /Forbidden.RAM: User not authorized to operate on the specified resource, or this API doesn't support RAM/
  70. * @throws ClientException
  71. * @throws ServerException
  72. */
  73. public function testCdn()
  74. {
  75. $result = (new DescribeCdnServiceRequest())
  76. ->client($this->clientName)
  77. ->connectTimeout(25)
  78. ->timeout(30)
  79. ->request();
  80. // static::assertArrayHasKey('ChangingChargeType', $result);
  81. }
  82. /**
  83. * @throws ClientException
  84. * @throws ServerException
  85. */
  86. public function testVpc()
  87. {
  88. $result = (new DescribeVpcsRequest())
  89. ->client($this->clientName)
  90. ->connectTimeout(25)
  91. ->timeout(30)
  92. ->request();
  93. static::assertArrayHasKey('Vpcs', $result);
  94. }
  95. }