EcsRamRoleCredentialTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
  6. /**
  7. * Class EcsRamRoleCredentialTest
  8. *
  9. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials
  10. *
  11. * @coversDefaultClass \AlibabaCloud\Client\Credentials\EcsRamRoleCredential
  12. */
  13. class EcsRamRoleCredentialTest extends TestCase
  14. {
  15. /**
  16. * @throws ClientException
  17. */
  18. public function testConstruct()
  19. {
  20. // Setup
  21. $roleName = 'role_arn';
  22. $expected = "roleName#$roleName";
  23. // Test
  24. $credential = new EcsRamRoleCredential($roleName);
  25. // Assert
  26. $this->assertEquals($roleName, $credential->getRoleName());
  27. $this->assertEquals($expected, (string)$credential);
  28. }
  29. /**
  30. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  31. * @expectedExceptionMessage Role Name cannot be empty
  32. * @throws ClientException
  33. */
  34. public function testRoleNameEmpty()
  35. {
  36. // Setup
  37. $roleName = '';
  38. // Test
  39. new EcsRamRoleCredential($roleName);
  40. }
  41. /**
  42. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  43. * @expectedExceptionMessage Role Name must be a string
  44. * @throws ClientException
  45. */
  46. public function testRoleNameFormat()
  47. {
  48. // Setup
  49. $roleName = null;
  50. // Test
  51. new EcsRamRoleCredential($roleName);
  52. }
  53. }