OssClientAsyncProcessObjectTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (PHP_VERSION_ID < 80500) {
  25. curl_close($ch);
  26. }
  27. fclose($fp);
  28. $this->local_file = $file_name;
  29. $this->object = "oss-example.mp4";
  30. Common::waitMetaSync();
  31. $this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
  32. }
  33. protected function tearDown(): void
  34. {
  35. parent::tearDown();
  36. unlink($this->local_file);
  37. }
  38. public function testAsyncProcessObject()
  39. {
  40. try {
  41. $object = 'php-async-copy';
  42. $process = 'video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1'.
  43. '|sys/saveas'.
  44. ',o_'.$this->base64url_encode($object).
  45. ',b_'.$this->base64url_encode($this->bucketName);
  46. $result = $this->client->asyncProcessObject($this->bucketName, $this->object, $process);
  47. }catch (OssException $e){
  48. $this->assertEquals($e->getErrorCode(),"Imm Client");
  49. $this->assertTrue(strpos($e->getErrorMessage(), "ResourceNotFound, The specified resource Attachment is not found") !== false);
  50. }
  51. }
  52. private function base64url_encode($data)
  53. {
  54. return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
  55. }
  56. }