BearerTokenCredentialTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\BearerTokenCredential;
  6. /**
  7. * Class BearerTokenCredentialTest
  8. *
  9. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials
  10. *
  11. * @coversDefaultClass \AlibabaCloud\Client\Credentials\BearerTokenCredential
  12. */
  13. class BearerTokenCredentialTest extends TestCase
  14. {
  15. /**
  16. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  17. * @expectedExceptionMessage Bearer Token cannot be empty
  18. * @throws ClientException
  19. */
  20. public static function testBearerTokenEmpty()
  21. {
  22. // Setup
  23. $bearerToken = '';
  24. // Test
  25. new BearerTokenCredential($bearerToken);
  26. }
  27. /**
  28. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  29. * @expectedExceptionMessage Bearer Token must be a string
  30. * @throws ClientException
  31. */
  32. public static function testBearerTokenFormat()
  33. {
  34. // Setup
  35. $bearerToken = null;
  36. // Test
  37. new BearerTokenCredential($bearerToken);
  38. }
  39. /**
  40. * @throws ClientException
  41. */
  42. public function testConstruct()
  43. {
  44. // Setup
  45. $bearerToken = 'BEARER_TOKEN';
  46. $expected = 'bearerToken#BEARER_TOKEN';
  47. // Test
  48. $credential = new BearerTokenCredential($bearerToken);
  49. // Assert
  50. $this->assertEquals($bearerToken, $credential->getBearerToken());
  51. $this->assertEquals('', $credential->getAccessKeyId());
  52. $this->assertEquals('', $credential->getAccessKeySecret());
  53. $this->assertEquals($expected, (string)$credential);
  54. }
  55. }