Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Tests\Feature;
use Tests\TestCase;
use File;
use Symfony\Component\Process\Process;
use Illuminate\Support\Facades\Storage;
class FetchVideoTest extends TestCase
{
/** @test **/
public function a_user_can_fetch_his_videos()
{
$ffmpegBinary = config('medialibrary.ffmpeg_path');
$filename = uniqid() . '.mp4';
$directory = storage_path("app/public/{$user->id}");
$fileRootPath = storage_path("app/public/{$user->id}/{$filename}");
if (!File::isDirectory($directory)) {
File::makeDirectory($directory, 0777, true, true);
}
$command = "{$ffmpegBinary} -f lavfi -i smptebars=duration=10:size=640x360:rate=30 {$fileRootPath}";
$process = new Process($command);
$process->run();
$file = \Illuminate\Http\UploadedFile::createFromBase(
(new \Symfony\Component\HttpFoundation\File\UploadedFile(
$fileRootPath,
$filename,
'video/mp4',
1993588,
null,
true
))
);
$this->postJson(route('video.upload'), [
'id' => $user->id,
'media' => $file,
])->assertSuccessful();
Storage::disk('public')->assertExists("{$user->id}/{$filename}");
File::delete($fileWithExt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.