123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Pbmedia\LaravelFFMpeg\Tests;
- use Illuminate\Config\Repository as ConfigRepository;
- use Illuminate\Contracts\Filesystem\Factory as Filesystems;
- use Illuminate\Filesystem\FilesystemAdapter;
- use Illuminate\Log\Logger as Writer;
- use League\Flysystem\Adapter\Ftp;
- use League\Flysystem\Adapter\Local;
- use League\Flysystem\Filesystem as Flysystem;
- use Mockery;
- use Monolog\Logger;
- use Pbmedia\LaravelFFMpeg\FFMpeg;
- use PHPUnit\Framework\TestCase as PHPUnitTestCase;
- class TestCase extends PHPUnitTestCase
- {
- public $srcDir;
- public $remoteFilesystem;
- public function setUp()
- {
- $this->srcDir = __DIR__ . '/src';
- $this->remoteFilesystem = false;
- }
- public function getDefaultConfig()
- {
- if (php_uname('s') === "Darwin") {
- return require __DIR__ . '/../config/laravel-ffmpeg-mac-brew.php';
- }
- return require __DIR__ . '/../config/laravel-ffmpeg-ubuntu.php';
- }
- public function getLocalAdapter(): FilesystemAdapter
- {
- $flysystem = new Flysystem(new Local($this->srcDir));
- return new FilesystemAdapter($flysystem);
- }
- public function getFtpAdapter(): FilesystemAdapter
- {
- $flysystem = new Flysystem(new Ftp([]));
- return new FilesystemAdapter($flysystem);
- }
- public function getFilesystems(): Filesystems
- {
- $filesystems = Mockery::mock(Filesystems::class);
- if ($this->remoteFilesystem) {
- $filesystems->shouldReceive('disk')->once()->with('s3')->andReturn($this->getFtpAdapter());
- } else {
- $filesystems->shouldReceive('disk')->once()->with('local')->andReturn($this->getLocalAdapter());
- }
- return $filesystems;
- }
- public function getService(): FFMpeg
- {
- $filesystems = $this->getFilesystems();
- $logger = new Writer(new Logger('ffmpeg'));
- $config = Mockery::mock(ConfigRepository::class);
- $filesystems->shouldReceive('disk')->once()->with('local')->andReturn($this->getLocalAdapter());
- $config->shouldReceive('get')->once()->with('laravel-ffmpeg')->andReturn($this->getDefaultConfig());
- $config->shouldReceive('get')->once()->with('filesystems.default')->andReturn('local');
- return new FFMpeg($filesystems, $config, $logger);
- }
- public function getGuitarMedia()
- {
- $service = $this->getService();
- return $service->open('guitar.m4a');
- }
- public function getVideoMedia()
- {
- $service = $this->getService();
- return $service->open('video.mp4');
- }
- }
|