Skip to content

Commit

Permalink
Added ‘withVisibility’ method in MediaExporter
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Aug 31, 2017
1 parent 90f2a93 commit a36dd18
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/MediaExporter.php
Expand Up @@ -12,6 +12,8 @@ class MediaExporter

protected $format;

protected $visibility;

protected $saveMethod = 'saveAudioOrVideo';

public function __construct(Media $media)
Expand Down Expand Up @@ -49,20 +51,32 @@ public function toDisk($diskOrName): MediaExporter
return $this;
}

public function withVisibility(string $visibility = null)
{
$this->visibility = $visibility;

return $this;
}

public function save(string $path): Media
{
$file = $this->getDisk()->newFile($path);
$disk = $this->getDisk();
$file = $disk->newFile($path);

$destinationPath = $this->getDestinationPathForSaving($file);

$this->createDestinationPathForSaving($file);

$this->{$this->saveMethod}($destinationPath);

if (!$this->getDisk()->isLocal()) {
if (!$disk->isLocal()) {
$this->moveSavedFileToRemoteDisk($destinationPath, $file);
}

if ($this->visibility) {
$disk->setVisibility($path, $this->visibility);
}

return $this->media;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/AudioVideoTest.php
Expand Up @@ -12,6 +12,7 @@
use FFMpeg\Media\Video;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Filesystem\Factory as Filesystems;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Log\Writer;
use Illuminate\Support\Fluent;
Expand Down Expand Up @@ -259,6 +260,40 @@ public function testExportingToRemoteDisk()
$exporter->inFormat($format)->toDisk($mockedRemoteDisk)->save('guitar_aac.aac');
}

public function testExportingToRemoteDiskWithPublicVisibility()
{
$this->remoteFilesystem = true;

$guitarFile = $this->getGuitarMedia()->getFile();

$baseMedia = Mockery::mock(Video::class);
$baseMedia->shouldReceive('save')->once();

$media = new Media($guitarFile, $baseMedia);

$exporter = new MediaExporter($media);

$mockedRemoteDisk = Mockery::mock(Disk::class);
$remoteFile = new File($mockedRemoteDisk, 'guitar_aac.aac');

$remoteFileMocked = Mockery::mock(File::class);

$remoteFileMocked->shouldReceive('getPath')->once()->andReturn($remoteFile->getPath());
$remoteFileMocked->shouldReceive('getDisk')->once()->andReturn($remoteFile->getDisk());
$remoteFileMocked->shouldReceive('getExtension')->once()->andReturn($remoteFile->getExtension());
$remoteFileMocked->shouldReceive('put')->once()->andReturn(true);

$mockedRemoteDisk->shouldReceive('isLocal')->once()->andReturn(false);
$mockedRemoteDisk->shouldReceive('newFile')->once()->withArgs(['guitar_aac.aac'])->andReturn($remoteFileMocked);
$mockedRemoteDisk->shouldReceive('setVisibility')->once()->withArgs(['guitar_aac.aac', Filesystem::VISIBILITY_PUBLIC]);

$format = new \FFMpeg\Format\Audio\Aac;
$exporter->inFormat($format)
->toDisk($mockedRemoteDisk)
->withVisibility(Filesystem::VISIBILITY_PUBLIC)
->save('guitar_aac.aac');
}

public function testCreatingAndUnlinkingOfTemporaryFiles()
{
$newTemporaryFile = FFMpeg::newTemporaryFile();
Expand Down

0 comments on commit a36dd18

Please sign in to comment.