Created
October 1, 2019 05:58
-
-
Save allaniftrue/e14f7babe31252a459d7129b236e377c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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