diff --git a/templates/php/src/VideoUploader.php b/templates/php/src/VideoUploader.php index 3b63bcef..1141fc42 100644 --- a/templates/php/src/VideoUploader.php +++ b/templates/php/src/VideoUploader.php @@ -53,7 +53,8 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin return $this->execute( '/upload?token='.$token, $file, - $this->getChunkSize($contentRange) + $this->getChunkSize($contentRange), + $videoId ); } @@ -65,14 +66,13 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin * @return Video * @throws ClientExceptionInterface */ - private function execute(string $path, \SplFileObject $file, int $chunkSize): Video + private function execute(string $path, \SplFileObject $file, int $chunkSize, string $videoId = null): Video { $start = 0; $fileSize = filesize($file->getRealPath()); $handle = fopen($file->getRealPath(), 'r'); $response = null; - $videoId = null; $part = 1; $partsCount = ceil($fileSize / $chunkSize); diff --git a/templates/php/statics/.github/workflows/test.yml b/templates/php/statics/.github/workflows/test.yml index 998f124c..362ce349 100644 --- a/templates/php/statics/.github/workflows/test.yml +++ b/templates/php/statics/.github/workflows/test.yml @@ -13,11 +13,11 @@ jobs: - name: Install dependancies uses: php-actions/composer@v5 with: - php_version: 7.3 + php_version: 8.1 - name: PHPUnit tests uses: php-actions/phpunit@v2 env: API_KEY: ${{ secrets.API_KEY }} BASE_URI: https://sandbox.api.video with: - args: tests \ No newline at end of file + args: tests --log_junit \ No newline at end of file diff --git a/templates/php/tests/Api/VideosApiTest.php b/templates/php/tests/Api/VideosApiTest.php index cf820177..ef16e55b 100644 --- a/templates/php/tests/Api/VideosApiTest.php +++ b/templates/php/tests/Api/VideosApiTest.php @@ -258,6 +258,33 @@ public function testUploadThumbnail() $this->assertEquals('thumbnail.jpg', basename($video->getAssets()->getThumbnail())); } + public function testUploadWithUploadTokenWithVideoId() + { + $token = (new Helper($this->client))->createUploadToken(); + + $video = $this->client->videos()->create((new VideoCreationPayload()) + ->setTitle('Test video creation') + ->setDescription('Test description')); + + // No authorization needed for this endpoint + $client = new Client( + $_ENV['BASE_URI'], + null, + new Psr18Client() + ); + + $uploadedVideo = $client->videos()->uploadWithUploadToken( + $token->getToken(), + new SplFileObject(__DIR__ . '/../resources/558k.mp4'), + null, + $video->getVideoId() + ); + + $this->client->uploadTokens()->deleteToken($token->getToken()); + + $this->assertNotNull($uploadedVideo->getAssets()->getPlayer()); + } + public function testUploadWithUploadToken() { $token = (new Helper($this->client))->createUploadToken(); @@ -274,6 +301,8 @@ public function testUploadWithUploadToken() new SplFileObject(__DIR__ . '/../resources/558k.mp4') ); + $this->client->uploadTokens()->deleteToken($token->getToken()); + $this->assertNotNull($uploadedVideo->getAssets()->getPlayer()); } }