TestCase.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Pbmedia\LaravelFFMpeg\Tests;
  3. use Illuminate\Config\Repository as ConfigRepository;
  4. use Illuminate\Contracts\Filesystem\Factory as Filesystems;
  5. use Illuminate\Filesystem\FilesystemAdapter;
  6. use Illuminate\Log\Logger as Writer;
  7. use League\Flysystem\Adapter\Ftp;
  8. use League\Flysystem\Adapter\Local;
  9. use League\Flysystem\Filesystem as Flysystem;
  10. use Mockery;
  11. use Monolog\Logger;
  12. use Pbmedia\LaravelFFMpeg\FFMpeg;
  13. use PHPUnit\Framework\TestCase as PHPUnitTestCase;
  14. class TestCase extends PHPUnitTestCase
  15. {
  16. public $srcDir;
  17. public $remoteFilesystem;
  18. public function setUp()
  19. {
  20. $this->srcDir = __DIR__ . '/src';
  21. $this->remoteFilesystem = false;
  22. }
  23. public function getDefaultConfig()
  24. {
  25. if (php_uname('s') === "Darwin") {
  26. return require __DIR__ . '/../config/laravel-ffmpeg-mac-brew.php';
  27. }
  28. return require __DIR__ . '/../config/laravel-ffmpeg-ubuntu.php';
  29. }
  30. public function getLocalAdapter(): FilesystemAdapter
  31. {
  32. $flysystem = new Flysystem(new Local($this->srcDir));
  33. return new FilesystemAdapter($flysystem);
  34. }
  35. public function getFtpAdapter(): FilesystemAdapter
  36. {
  37. $flysystem = new Flysystem(new Ftp([]));
  38. return new FilesystemAdapter($flysystem);
  39. }
  40. public function getFilesystems(): Filesystems
  41. {
  42. $filesystems = Mockery::mock(Filesystems::class);
  43. if ($this->remoteFilesystem) {
  44. $filesystems->shouldReceive('disk')->once()->with('s3')->andReturn($this->getFtpAdapter());
  45. } else {
  46. $filesystems->shouldReceive('disk')->once()->with('local')->andReturn($this->getLocalAdapter());
  47. }
  48. return $filesystems;
  49. }
  50. public function getService(): FFMpeg
  51. {
  52. $filesystems = $this->getFilesystems();
  53. $logger = new Writer(new Logger('ffmpeg'));
  54. $config = Mockery::mock(ConfigRepository::class);
  55. $filesystems->shouldReceive('disk')->once()->with('local')->andReturn($this->getLocalAdapter());
  56. $config->shouldReceive('get')->once()->with('laravel-ffmpeg')->andReturn($this->getDefaultConfig());
  57. $config->shouldReceive('get')->once()->with('filesystems.default')->andReturn('local');
  58. return new FFMpeg($filesystems, $config, $logger);
  59. }
  60. public function getGuitarMedia()
  61. {
  62. $service = $this->getService();
  63. return $service->open('guitar.m4a');
  64. }
  65. public function getVideoMedia()
  66. {
  67. $service = $this->getService();
  68. return $service->open('video.mp4');
  69. }
  70. }