AccessKeyCredentialTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\Unit\Credentials;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Credentials\AccessKeyCredential;
  6. /**
  7. * Class AccessKeyCredentialTest
  8. *
  9. * @package AlibabaCloud\Client\Tests\Unit\Credentials
  10. *
  11. * @coversDefaultClass \AlibabaCloud\Client\Credentials\AccessKeyCredential
  12. */
  13. class AccessKeyCredentialTest extends TestCase
  14. {
  15. /**
  16. * @throws ClientException
  17. */
  18. public function testConstruct()
  19. {
  20. // Setup
  21. $accessKeyId = 'foo';
  22. $accessKeySecret = 'bar';
  23. // Test
  24. $credential = new AccessKeyCredential($accessKeyId, $accessKeySecret);
  25. // Assert
  26. $this->assertEquals($accessKeyId, $credential->getAccessKeyId());
  27. $this->assertEquals($accessKeySecret, $credential->getAccessKeySecret());
  28. $this->assertEquals("$accessKeyId#$accessKeySecret", (string)$credential);
  29. }
  30. /**
  31. * @throws ClientException
  32. */
  33. public function testAccessKeyIdEmpty()
  34. {
  35. $this->expectException(ClientException::class);
  36. $this->expectExceptionMessage('AccessKey ID cannot be empty');
  37. // Setup
  38. $accessKeyId = '';
  39. $accessKeySecret = 'bar';
  40. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  41. }
  42. /**
  43. * @throws ClientException
  44. */
  45. public function testAccessKeyIdFormat()
  46. {
  47. $this->expectException(ClientException::class);
  48. $this->expectExceptionMessage('AccessKey ID must be a string');
  49. // Setup
  50. $accessKeyId = null;
  51. $accessKeySecret = 'bar';
  52. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  53. }
  54. /**
  55. * @throws ClientException
  56. */
  57. public function testAccessKeySecretEmpty()
  58. {
  59. $this->expectException(ClientException::class);
  60. $this->expectExceptionMessage('AccessKey Secret cannot be empty');
  61. // Setup
  62. $accessKeyId = 'foo';
  63. $accessKeySecret = '';
  64. // Test
  65. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  66. }
  67. /**
  68. * @throws ClientException
  69. */
  70. public function testAccessKeySecretFormat()
  71. {
  72. $this->expectException(ClientException::class);
  73. $this->expectExceptionMessage('AccessKey Secret must be a string');
  74. // Setup
  75. $accessKeyId = 'foo';
  76. $accessKeySecret = null;
  77. // Test
  78. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  79. }
  80. }