Skip to content

Commit 81e6857

Browse files
committed
feat(php) upload with token and videoId
1 parent f0d51c5 commit 81e6857

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

templates/php/src/VideoUploader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin
5353
return $this->execute(
5454
'/upload?token='.$token,
5555
$file,
56-
$this->getChunkSize($contentRange)
56+
$this->getChunkSize($contentRange),
57+
$videoId
5758
);
5859
}
5960

@@ -65,14 +66,13 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin
6566
* @return Video
6667
* @throws ClientExceptionInterface
6768
*/
68-
private function execute(string $path, \SplFileObject $file, int $chunkSize): Video
69+
private function execute(string $path, \SplFileObject $file, int $chunkSize, string $videoId = null): Video
6970
{
7071
$start = 0;
7172
$fileSize = filesize($file->getRealPath());
7273
$handle = fopen($file->getRealPath(), 'r');
7374

7475
$response = null;
75-
$videoId = null;
7676
$part = 1;
7777
$partsCount = ceil($fileSize / $chunkSize);
7878

templates/php/statics/.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- name: Install dependancies
1414
uses: php-actions/composer@v5
1515
with:
16-
php_version: 7.3
16+
php_version: 8.1
1717
- name: PHPUnit tests
1818
uses: php-actions/phpunit@v2
1919
env:
2020
API_KEY: ${{ secrets.API_KEY }}
2121
BASE_URI: https://sandbox.api.video
2222
with:
23-
args: tests
23+
args: tests --log_junit output.xml

templates/php/tests/Api/VideosApiTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,33 @@ public function testUploadThumbnail()
258258
$this->assertEquals('thumbnail.jpg', basename($video->getAssets()->getThumbnail()));
259259
}
260260

261+
public function testUploadWithUploadTokenWithVideoId()
262+
{
263+
$token = (new Helper($this->client))->createUploadToken();
264+
265+
$video = $this->client->videos()->create((new VideoCreationPayload())
266+
->setTitle('Test video creation')
267+
->setDescription('Test description'));
268+
269+
// No authorization needed for this endpoint
270+
$client = new Client(
271+
$_ENV['BASE_URI'],
272+
null,
273+
new Psr18Client()
274+
);
275+
276+
$uploadedVideo = $client->videos()->uploadWithUploadToken(
277+
$token->getToken(),
278+
new SplFileObject(__DIR__ . '/../resources/558k.mp4'),
279+
null,
280+
$video->getVideoId()
281+
);
282+
283+
$this->client->uploadTokens()->deleteToken($token->getToken());
284+
285+
$this->assertNotNull($uploadedVideo->getAssets()->getPlayer());
286+
}
287+
261288
public function testUploadWithUploadToken()
262289
{
263290
$token = (new Helper($this->client))->createUploadToken();
@@ -274,6 +301,8 @@ public function testUploadWithUploadToken()
274301
new SplFileObject(__DIR__ . '/../resources/558k.mp4')
275302
);
276303

304+
$this->client->uploadTokens()->deleteToken($token->getToken());
305+
277306
$this->assertNotNull($uploadedVideo->getAssets()->getPlayer());
278307
}
279308
}

0 commit comments

Comments
 (0)