OssClientAsyncProcessObjectTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace OSS\Tests;
  3. require_once __DIR__ . '/Common.php';
  4. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  5. use OSS\Core\OssException;
  6. class OssClientAsyncProcessObjectTest extends TestOssClientBase
  7. {
  8. private $bucketName;
  9. private $client;
  10. private $local_file;
  11. private $object;
  12. private $download_file;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->client = $this->ossClient;
  17. $this->bucketName = $this->bucket;
  18. $url = 'https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/video.mp4?spm=a2c4g.64555.0.0.515675979u4B8w&file=video.mp4';
  19. $file_name = "video.mp4";
  20. $fp = fopen($file_name, 'w');
  21. $ch = curl_init($url);
  22. curl_setopt($ch, CURLOPT_FILE, $fp);
  23. curl_exec($ch);
  24. curl_close($ch);
  25. fclose($fp);
  26. $this->local_file = $file_name;
  27. $this->object = "oss-example.mp4";
  28. Common::waitMetaSync();
  29. $this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
  30. }
  31. protected function tearDown(): void
  32. {
  33. parent::tearDown();
  34. unlink($this->local_file);
  35. }
  36. public function testAsyncProcessObject()
  37. {
  38. try {
  39. $object = 'php-async-copy';
  40. $process = 'video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1'.
  41. '|sys/saveas'.
  42. ',o_'.$this->base64url_encode($object).
  43. ',b_'.$this->base64url_encode($this->bucketName);
  44. $result = $this->client->asyncProcessObject($this->bucketName, $this->object, $process);
  45. }catch (OssException $e){
  46. $this->assertEquals($e->getErrorCode(),"Imm Client");
  47. $this->assertTrue(strpos($e->getErrorMessage(), "ResourceNotFound, The specified resource Attachment is not found") !== false);
  48. }
  49. }
  50. private function base64url_encode($data)
  51. {
  52. return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
  53. }
  54. }