AccessKeyCredentialTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\AccessKeyCredential;
  6. /**
  7. * Class AccessKeyCredentialTest
  8. *
  9. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\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. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  32. * @expectedExceptionMessage AccessKey ID cannot be empty
  33. * @throws ClientException
  34. */
  35. public function testAccessKeyIdEmpty()
  36. {
  37. // Setup
  38. $accessKeyId = '';
  39. $accessKeySecret = 'bar';
  40. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  41. }
  42. /**
  43. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  44. * @expectedExceptionMessage AccessKey ID must be a string
  45. * @throws ClientException
  46. */
  47. public function testAccessKeyIdFormat()
  48. {
  49. // Setup
  50. $accessKeyId = null;
  51. $accessKeySecret = 'bar';
  52. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  53. }
  54. /**
  55. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  56. * @expectedExceptionMessage AccessKey Secret cannot be empty
  57. * @throws ClientException
  58. */
  59. public function testAccessKeySecretEmpty()
  60. {
  61. // Setup
  62. $accessKeyId = 'foo';
  63. $accessKeySecret = '';
  64. // Test
  65. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  66. }
  67. /**
  68. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  69. * @expectedExceptionMessage AccessKey Secret must be a string
  70. * @throws ClientException
  71. */
  72. public function testAccessKeySecretFormat()
  73. {
  74. // Setup
  75. $accessKeyId = 'foo';
  76. $accessKeySecret = null;
  77. // Test
  78. new AccessKeyCredential($accessKeyId, $accessKeySecret);
  79. }
  80. }