OssClientBucketLifecycleTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. use OSS\Model\LifecycleConfig;
  5. use OSS\Model\LifecycleRule;
  6. use OSS\Model\LifecycleAction;
  7. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  8. class OssClientBucketLifecycleTest extends TestOssClientBase
  9. {
  10. public function testBucket()
  11. {
  12. $lifecycleConfig = new LifecycleConfig();
  13. $actions = array();
  14. $actions[] = new LifecycleAction("Expiration", "Days", 3);
  15. $lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
  16. $lifecycleConfig->addRule($lifecycleRule);
  17. $actions = array();
  18. $actions[] = new LifecycleAction("Expiration", "Date", '2022-10-12T00:00:00.000Z');
  19. $lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
  20. $lifecycleConfig->addRule($lifecycleRule);
  21. try {
  22. $this->ossClient->putBucketLifecycle($this->bucket, $lifecycleConfig);
  23. } catch (OssException $e) {
  24. $this->assertTrue(false);
  25. }
  26. try {
  27. Common::waitMetaSync();
  28. $lifecycleConfig2 = $this->ossClient->getBucketLifecycle($this->bucket);
  29. $this->assertEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig2->serializeToXml());
  30. } catch (OssException $e) {
  31. $this->assertTrue(false);
  32. }
  33. try {
  34. Common::waitMetaSync();
  35. $this->ossClient->deleteBucketLifecycle($this->bucket);
  36. } catch (OssException $e) {
  37. $this->assertTrue(false);
  38. }
  39. try {
  40. Common::waitMetaSync();
  41. $lifecycleConfig3 = $this->ossClient->getBucketLifecycle($this->bucket);
  42. $this->assertNotEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig3->serializeToXml());
  43. } catch (OssException $e) {
  44. $this->assertTrue(false);
  45. }
  46. }
  47. }