EcsRamRoleCredentialTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Dds\DescribeRegionsRequest;
  8. /**
  9. * Class EcsRamRoleCredentialTest
  10. *
  11. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials
  12. */
  13. class EcsRamRoleCredentialTest extends TestCase
  14. {
  15. /**
  16. * @var string
  17. */
  18. private $clientName = 'EcsRamRoleCredentialTest';
  19. /**
  20. * Sets up the fixture, for example, open a network connection.
  21. * This method is called before a test is executed.
  22. *
  23. * @throws ClientException
  24. */
  25. public function setUp()
  26. {
  27. $regionId = 'cn-hangzhou';
  28. $roleName = 'EcsRamRoleTest';
  29. AlibabaCloud::ecsRamRoleClient($roleName)
  30. ->regionId($regionId)
  31. ->name($this->clientName);
  32. }
  33. /**
  34. * Tears down the fixture, for example, close a network connection.
  35. * This method is called after a test is executed.
  36. *
  37. * @throws ClientException
  38. */
  39. public function tearDown()
  40. {
  41. AlibabaCloud::del($this->clientName);
  42. }
  43. /**
  44. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  45. * @expectedExceptionMessage Timeout or instance does not belong to Alibaba Cloud
  46. * @throws ClientException
  47. */
  48. public function testGetSessionCredential()
  49. {
  50. try {
  51. (new DescribeRegionsRequest())->client($this->clientName)
  52. ->connectTimeout(25)
  53. ->timeout(30)
  54. ->request();
  55. } catch (ServerException $e) {
  56. self::assertContains(
  57. $e->getErrorMessage(),
  58. [
  59. 'Error in retrieving assume role credentials.',
  60. 'The role was not found in the instance',
  61. ]
  62. );
  63. }
  64. }
  65. }