OssClientBucketTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. use OSS\Core\OssUtil;
  5. use OSS\OssClient;
  6. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  7. class OssClientBucketTest extends TestOssClientBase
  8. {
  9. public function testBucketWithInvalidName()
  10. {
  11. try {
  12. $this->ossClient->createBucket("s");
  13. $this->assertFalse(true);
  14. } catch (OssException $e) {
  15. $this->assertEquals('"s"bucket name is invalid', $e->getMessage());
  16. }
  17. }
  18. public function testBucketWithInvalidACL()
  19. {
  20. try {
  21. $this->ossClient->createBucket($this->bucket, "invalid");
  22. $this->assertFalse(true);
  23. } catch (OssException $e) {
  24. $this->assertEquals('invalid:acl is invalid(private,public-read,public-read-write)', $e->getMessage());
  25. }
  26. }
  27. public function testBucket()
  28. {
  29. $this->ossClient->createBucket($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
  30. $bucketListInfo = $this->ossClient->listBuckets();
  31. $this->assertNotNull($bucketListInfo);
  32. $bucketList = $bucketListInfo->getBucketList();
  33. $this->assertTrue(is_array($bucketList));
  34. $this->assertGreaterThan(0, count($bucketList));
  35. $this->ossClient->putBucketAcl($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
  36. Common::waitMetaSync();
  37. $this->assertEquals($this->ossClient->getBucketAcl($this->bucket), OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
  38. $this->assertTrue($this->ossClient->doesBucketExist($this->bucket));
  39. $this->assertFalse($this->ossClient->doesBucketExist($this->bucket . '-notexist'));
  40. try {
  41. $this->ossClient->deleteBucket($this->bucket);
  42. } catch (OssException $e) {
  43. $this->assertEquals("BucketNotEmpty", $e->getErrorCode());
  44. $this->assertEquals("409", $e->getHTTPStatus());
  45. }
  46. }
  47. }