OssClientRestoreObjectTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. use OSS\OssClient;
  5. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  6. class OssClientRestoreObjectTest extends TestOssClientBase
  7. {
  8. private $iaBucket;
  9. private $archiveBucket;
  10. public function testIARestoreObject()
  11. {
  12. $object = 'storage-object';
  13. $this->ossClient->putObject($this->iaBucket, $object,'testcontent');
  14. try{
  15. $this->ossClient->restoreObject($this->iaBucket, $object);
  16. $this->assertTrue(false);
  17. }catch (OssException $e){
  18. $this->assertEquals('400', $e->getHTTPStatus());
  19. $this->assertEquals('OperationNotSupported', $e->getErrorCode());
  20. }
  21. }
  22. public function testNullObjectRestoreObject()
  23. {
  24. $object = 'null-object';
  25. try{
  26. $this->ossClient->restoreObject($this->bucket, $object);
  27. $this->assertTrue(false);
  28. }catch (OssException $e){
  29. $this->assertEquals('404', $e->getHTTPStatus());
  30. }
  31. }
  32. public function testArchiveRestoreObject()
  33. {
  34. $object = 'storage-object';
  35. $this->ossClient->putObject($this->archiveBucket, $object,'testcontent');
  36. try{
  37. $this->ossClient->getObject($this->archiveBucket, $object);
  38. $this->assertTrue(false);
  39. }catch (OssException $e){
  40. $this->assertEquals('403', $e->getHTTPStatus());
  41. $this->assertEquals('InvalidObjectState', $e->getErrorCode());
  42. }
  43. $result = $this->ossClient->restoreObject($this->archiveBucket, $object);
  44. common::waitMetaSync();
  45. $this->assertEquals('202', $result['info']['http_code']);
  46. try{
  47. $this->ossClient->restoreObject($this->archiveBucket, $object);
  48. }catch(OssException $e){
  49. $this->assertEquals('409', $e->getHTTPStatus());
  50. $this->assertEquals('RestoreAlreadyInProgress', $e->getErrorCode());
  51. }
  52. }
  53. public function setUp()
  54. {
  55. parent::setUp();
  56. $this->iaBucket = 'ia-' . $this->bucket;
  57. $this->archiveBucket = 'archive-' . $this->bucket;
  58. $options = array(
  59. OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_IA
  60. );
  61. $this->ossClient->createBucket($this->iaBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
  62. $options = array(
  63. OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_ARCHIVE
  64. );
  65. $this->ossClient->createBucket($this->archiveBucket, OssClient::OSS_ACL_TYPE_PRIVATE, $options);
  66. }
  67. public function tearDown()
  68. {
  69. parent::tearDown();
  70. $object = 'storage-object';
  71. $this->ossClient->deleteObject($this->iaBucket, $object);
  72. $this->ossClient->deleteObject($this->archiveBucket, $object);
  73. $this->ossClient->deleteBucket($this->iaBucket);
  74. $this->ossClient->deleteBucket($this->archiveBucket);
  75. }
  76. }