EcsRamRoleClientTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Clients;
  3. use AlibabaCloud\Client\SDK;
  4. use PHPUnit\Framework\TestCase;
  5. use AlibabaCloud\Client\Clients\EcsRamRoleClient;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. use AlibabaCloud\Client\Exception\ServerException;
  8. use AlibabaCloud\Client\Signature\ShaHmac1Signature;
  9. use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
  10. /**
  11. * Class EcsRamRoleClientTest
  12. *
  13. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Clients
  14. */
  15. class EcsRamRoleClientTest extends TestCase
  16. {
  17. /**
  18. * @return EcsRamRoleClient
  19. * @throws ClientException
  20. */
  21. public function testConstruct()
  22. {
  23. // Setup
  24. $roleName = 'EcsRamRoleTest';
  25. // Test
  26. $client = new EcsRamRoleClient($roleName);
  27. // Assert
  28. self::assertEquals($roleName, $client->getCredential()->getRoleName());
  29. self::assertInstanceOf(EcsRamRoleCredential::class, $client->getCredential());
  30. self::assertInstanceOf(ShaHmac1Signature::class, $client->getSignature());
  31. return $client;
  32. }
  33. /**
  34. * @depends testConstruct
  35. *
  36. * @param EcsRamRoleClient $client
  37. *
  38. * @throws ServerException
  39. */
  40. public function testGetSessionCredential(EcsRamRoleClient $client)
  41. {
  42. try {
  43. $client->getSessionCredential(1);
  44. } catch (ClientException $exception) {
  45. self::assertEquals($exception->getErrorCode(), SDK::SERVER_UNREACHABLE);
  46. }
  47. }
  48. }