OssClientTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. use OSS\OssClient;
  5. class OssClientTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testConstrunct()
  8. {
  9. try {
  10. $ossClient = new OssClient('id', 'key', 'http://oss-cn-hangzhou.aliyuncs.com');
  11. $this->assertFalse($ossClient->isUseSSL());
  12. $ossClient->setUseSSL(true);
  13. $this->assertTrue($ossClient->isUseSSL());
  14. $this->assertTrue(true);
  15. $this->assertEquals(3, $ossClient->getMaxRetries());
  16. $ossClient->setMaxTries(4);
  17. $this->assertEquals(4, $ossClient->getMaxRetries());
  18. $ossClient->setTimeout(10);
  19. $ossClient->setConnectTimeout(20);
  20. } catch (OssException $e) {
  21. assertFalse(true);
  22. }
  23. }
  24. public function testConstrunct2()
  25. {
  26. try {
  27. $ossClient = new OssClient('id', "", 'http://oss-cn-hangzhou.aliyuncs.com');
  28. $this->assertFalse(true);
  29. } catch (OssException $e) {
  30. $this->assertEquals("access key secret is empty", $e->getMessage());
  31. }
  32. }
  33. public function testConstrunct3()
  34. {
  35. try {
  36. $ossClient = new OssClient("", 'key', 'http://oss-cn-hangzhou.aliyuncs.com');
  37. $this->assertFalse(true);
  38. } catch (OssException $e) {
  39. $this->assertEquals("access key id is empty", $e->getMessage());
  40. }
  41. }
  42. public function testConstrunct4()
  43. {
  44. try {
  45. $ossClient = new OssClient('id', 'key', "");
  46. $this->assertFalse(true);
  47. } catch (OssException $e) {
  48. $this->assertEquals('endpoint is empty', $e->getMessage());
  49. }
  50. }
  51. public function testConstrunct5()
  52. {
  53. try {
  54. $ossClient = new OssClient('id', 'key', "123.123.123.1");
  55. } catch (OssException $e) {
  56. $this->assertTrue(false);
  57. }
  58. }
  59. public function testConstrunct6()
  60. {
  61. try {
  62. $ossClient = new OssClient('id', 'key', "https://123.123.123.1");
  63. $this->assertTrue($ossClient->isUseSSL());
  64. } catch (OssException $e) {
  65. $this->assertTrue(false);
  66. }
  67. }
  68. public function testConstrunct7()
  69. {
  70. try {
  71. $ossClient = new OssClient('id', 'key', "http://123.123.123.1");
  72. $this->assertFalse($ossClient->isUseSSL());
  73. } catch (OssException $e) {
  74. $this->assertTrue(false);
  75. }
  76. }
  77. public function testConstrunct8()
  78. {
  79. try {
  80. $ossClient = new OssClient('id', 'key', "http://123.123.123.1", true);
  81. $ossClient->listBuckets();
  82. $this->assertFalse(true);
  83. } catch (OssException $e) {
  84. }
  85. }
  86. public function testConstrunct9()
  87. {
  88. try {
  89. $accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
  90. $accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
  91. $endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
  92. $ossClient = new OssClient($accessKeyId, $accessKeySecret , $endpoint, false);
  93. $ossClient->listBuckets();
  94. } catch (OssException $e) {
  95. $this->assertFalse(true);
  96. }
  97. }
  98. }