FrameTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Pbmedia\LaravelFFMpeg\Tests;
  3. use Mockery;
  4. use Pbmedia\LaravelFFMpeg\Frame;
  5. use Pbmedia\LaravelFFMpeg\FrameExporter;
  6. class FrameTest extends TestCase
  7. {
  8. public function testGettingAFrameFromAString()
  9. {
  10. $media = $this->getVideoMedia();
  11. $frame = $media->getFrameFromString('00:00:12.47');
  12. $this->assertInstanceOf(Frame::class, $frame);
  13. $this->assertEquals((string) $frame->getTimeCode(), '00:00:12.47');
  14. }
  15. public function testGettingAFrameFromSeconds()
  16. {
  17. $media = $this->getVideoMedia();
  18. $frame = $media->getFrameFromSeconds(5);
  19. $this->assertInstanceOf(Frame::class, $frame);
  20. $this->assertEquals((string) $frame->getTimeCode(), '00:00:05.00');
  21. }
  22. public function testSettingTheAccuracy()
  23. {
  24. $media = $this->getVideoMedia();
  25. $frame = $media->getFrameFromSeconds(5);
  26. $exporter = $frame->export();
  27. $this->assertInstanceOf(FrameExporter::class, $exporter);
  28. $exporter->accurate();
  29. $this->assertTrue($exporter->getAccuracy());
  30. $exporter->unaccurate();
  31. $this->assertFalse($exporter->getAccuracy());
  32. }
  33. public function testExportingAFrame()
  34. {
  35. $file = $this->getVideoMedia()->getFile();
  36. $media = Mockery::mock(Frame::class);
  37. $media->shouldReceive('getFile')->once()->andReturn($file);
  38. $media->shouldReceive('isFrame')->once()->andReturn(true);
  39. $media->shouldReceive('save')->once()->withArgs([
  40. $this->srcDir . '/FrameAtThreeSeconds.png', false,
  41. ]);
  42. $exporter = new FrameExporter($media);
  43. $exporter->save('FrameAtThreeSeconds.png');
  44. }
  45. }