/vendor/php-ffmpeg/php-ffmpeg/tests/Unit/Format/Audio/AudioTestCase.php |
@@ -0,0 +1,124 @@ |
<?php |
|
namespace Tests\FFMpeg\Unit\Format\Audio; |
|
use Tests\FFMpeg\Unit\TestCase; |
use FFMpeg\Format\Audio\DefaultAudio; |
|
abstract class AudioTestCase extends TestCase |
{ |
public function testExtraParams() |
{ |
foreach ($this->getFormat()->getExtraParams() as $param) { |
$this->assertScalar($param); |
} |
} |
|
public function testGetAudioCodec() |
{ |
$this->assertScalar($this->getFormat()->getAudioCodec()); |
$this->assertContains($this->getFormat()->getAudioCodec(), $this->getFormat()->getAvailableAudioCodecs()); |
} |
|
public function testSetAudioCodec() |
{ |
$format = $this->getFormat(); |
|
foreach ($format->getAvailableAudioCodecs() as $codec) { |
$format->setAudioCodec($codec); |
$this->assertEquals($codec, $format->getAudioCodec()); |
} |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetInvalidAudioCodec() |
{ |
$this->getFormat()->setAudioCodec('invalid-random-audio-codec'); |
} |
|
public function testGetAvailableAudioCodecs() |
{ |
$this->assertGreaterThan(0, count($this->getFormat()->getAvailableAudioCodecs())); |
} |
|
public function testGetAudioKiloBitrate() |
{ |
$this->assertInternalType('integer', $this->getFormat()->getAudioKiloBitrate()); |
} |
|
public function testSetAudioKiloBitrate() |
{ |
$format = $this->getFormat(); |
$format->setAudioKiloBitrate(256); |
$this->assertEquals(256, $format->getAudioKiloBitrate()); |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetInvalidKiloBitrate() |
{ |
$this->getFormat()->setAudioKiloBitrate(0); |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetNegativeKiloBitrate() |
{ |
$this->getFormat()->setAudioKiloBitrate(-10); |
} |
|
public function testGetAudioChannels() |
{ |
$this->assertInternalType('null', $this->getFormat()->getAudioChannels()); |
} |
|
public function testSetAudioChannels() |
{ |
$format = $this->getFormat(); |
$format->setAudioChannels(2); |
$this->assertEquals(2, $format->getAudioChannels()); |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetInvalidChannels() |
{ |
$this->getFormat()->setAudioChannels(0); |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetNegativeChannels() |
{ |
$this->getFormat()->setAudioChannels(-10); |
} |
|
public function testCreateProgressListener() |
{ |
$media = $this->getMock('FFMpeg\Media\MediaTypeInterface'); |
$media->expects($this->any()) |
->method('getPathfile') |
->will($this->returnValue(__FILE__)); |
$format = $this->getFormat(); |
$ffprobe = $this->getFFProbeMock(); |
|
foreach ($format->createProgressListener($media, $ffprobe, 1, 3) as $listener) { |
$this->assertInstanceOf('FFMpeg\Format\ProgressListener\AudioProgressListener', $listener); |
$this->assertSame($ffprobe, $listener->getFFProbe()); |
$this->assertSame(__FILE__, $listener->getPathfile()); |
$this->assertSame(1, $listener->getCurrentPass()); |
$this->assertSame(3, $listener->getTotalPass()); |
} |
} |
|
/** |
* @return DefaultAudio |
*/ |
abstract public function getFormat(); |
} |
/vendor/php-ffmpeg/php-ffmpeg/tests/Unit/Format/ProgressListener/AudioProgressListenerTest.php |
@@ -0,0 +1,87 @@ |
<?php |
|
namespace Tests\FFMpeg\Unit\Format\ProgressListener; |
|
use Tests\FFMpeg\Unit\TestCase; |
use FFMpeg\Format\ProgressListener\AudioProgressListener; |
use FFMpeg\FFProbe\DataMapping\Format; |
|
class AudioProgressListenerTest extends TestCase |
{ |
/** |
* @dataProvider provideData |
*/ |
public function testHandle($size, $duration, |
$data, $expectedPercent, $expectedRemaining, $expectedRate, |
$data2, $expectedPercent2, $expectedRemaining2, $expectedRate2, |
$currentPass, $totalPass |
) |
{ |
$ffprobe = $this->getFFProbeMock(); |
$ffprobe->expects($this->once()) |
->method('format') |
->with(__FILE__) |
->will($this->returnValue(new Format(array( |
'size' => $size, |
'duration' => $duration, |
)))); |
|
$listener = new AudioProgressListener($ffprobe, __FILE__, $currentPass, $totalPass); |
$phpunit = $this; |
$n = 0; |
$listener->on('progress', function ($percent, $remaining, $rate) use (&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) { |
if (0 === $n) { |
$phpunit->assertEquals($expectedPercent, $percent); |
$phpunit->assertEquals($expectedRemaining, $remaining); |
$phpunit->assertEquals($expectedRate, $rate); |
} elseif (1 === $n) { |
$phpunit->assertEquals($expectedPercent2, $percent); |
$phpunit->assertEquals($expectedRemaining2, $remaining); |
$phpunit->assertLessThan($expectedRate2 + 3, $rate); |
$phpunit->assertGreaterThan($expectedRate2 - 3, $rate); |
} |
$n++; |
}); |
// first one does not trigger progress event |
$listener->handle('any-type'.mt_rand(), $data); |
sleep(1); |
$listener->handle('any-type'.mt_rand(), $data); |
sleep(1); |
$listener->handle('any-type'.mt_rand(), $data2); |
$this->assertEquals(2, $n); |
} |
|
public function provideData() |
{ |
return array( |
array( |
2894412, |
180.900750, |
'size= 712kB time=00:00:45.50 bitrate= 128.1kbits/s', |
25, |
0, |
0, |
'size= 1274kB time=00:01:29.32 bitrate= 142.8kbits/s', |
49, |
2, |
563, |
1, |
1 |
), |
array( |
2894412, |
180.900750, |
'size= 712kB time=00:00:45.50 bitrate= 128.1kbits/s', |
12, |
0, |
0, |
'size= 1274kB time=00:01:29.32 bitrate= 142.8kbits/s', |
24, |
2, |
563, |
1, |
2 |
) |
); |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/tests/Unit/Format/ProgressListener/VideoProgressListenerTest.php |
@@ -0,0 +1,87 @@ |
<?php |
|
namespace Tests\FFMpeg\Unit\Format\ProgressListener; |
|
use Tests\FFMpeg\Unit\TestCase; |
use FFMpeg\Format\ProgressListener\VideoProgressListener; |
use FFMpeg\FFProbe\DataMapping\Format; |
|
class VideoProgressListenerTest extends TestCase |
{ |
/** |
* @dataProvider provideData |
*/ |
public function testHandle($size, $duration, |
$data, $expectedPercent, $expectedRemaining, $expectedRate, |
$data2, $expectedPercent2, $expectedRemaining2, $expectedRate2, |
$currentPass, $totalPass |
) |
{ |
$ffprobe = $this->getFFProbeMock(); |
$ffprobe->expects($this->once()) |
->method('format') |
->with(__FILE__) |
->will($this->returnValue(new Format(array( |
'size' => $size, |
'duration' => $duration, |
)))); |
|
$listener = new VideoProgressListener($ffprobe, __FILE__, $currentPass, $totalPass); |
$phpunit = $this; |
$n = 0; |
$listener->on('progress', function ($percent, $remaining, $rate) use (&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) { |
if (0 === $n) { |
$phpunit->assertEquals($expectedPercent, $percent); |
$phpunit->assertEquals($expectedRemaining, $remaining); |
$phpunit->assertEquals($expectedRate, $rate); |
} elseif (1 === $n) { |
$phpunit->assertEquals($expectedPercent2, $percent); |
$phpunit->assertEquals($expectedRemaining2, $remaining); |
$phpunit->assertLessThan($expectedRate2 + 10, $rate); |
$phpunit->assertGreaterThan($expectedRate2 - 10, $rate); |
} |
$n++; |
}); |
// first one does not trigger progress event |
$listener->handle('any-type'.mt_rand(), $data); |
sleep(1); |
$listener->handle('any-type'.mt_rand(), $data); |
sleep(1); |
$listener->handle('any-type'.mt_rand(), $data2); |
$this->assertEquals(2, $n); |
} |
|
public function provideData() |
{ |
return array( |
array( |
147073958, |
281.147533, |
'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0', |
2, |
0, |
0, |
'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0', |
11, |
32, |
3868, |
1, |
1 |
), |
array( |
147073958, |
281.147533, |
'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0', |
1, |
0, |
0, |
'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0', |
5, |
32, |
3868, |
1, |
2 |
) |
); |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/tests/Unit/Format/Video/VideoTestCase.php |
@@ -0,0 +1,85 @@ |
<?php |
|
namespace Tests\FFMpeg\Unit\Format\Video; |
|
use Tests\FFMpeg\Unit\Format\Audio\AudioTestCase; |
|
abstract class VideoTestCase extends AudioTestCase |
{ |
public function testGetVideoCodec() |
{ |
$this->assertScalar($this->getFormat()->getVideoCodec()); |
$this->assertContains($this->getFormat()->getVideoCodec(), $this->getFormat()->getAvailableVideoCodecs()); |
} |
|
public function testSupportBFrames() |
{ |
$this->assertInternalType('boolean', $this->getFormat()->supportBFrames()); |
} |
|
public function testSetVideoCodec() |
{ |
$format = $this->getFormat(); |
|
foreach ($format->getAvailableVideoCodecs() as $codec) { |
$format->setVideoCodec($codec); |
$this->assertEquals($codec, $format->getVideoCodec()); |
} |
} |
|
public function testGetKiloBitrate() |
{ |
$this->assertInternalType('integer', $this->getFormat()->getKiloBitrate()); |
} |
|
public function testSetKiloBitrate() |
{ |
$format = $this->getFormat(); |
$format->setKiloBitrate(2560); |
$this->assertEquals(2560, $format->getKiloBitrate()); |
} |
|
/** |
* @expectedException FFMpeg\Exception\InvalidArgumentException |
*/ |
public function testSetInvalidVideoCodec() |
{ |
$this->getFormat()->setVideoCodec('invalid-random-video-codec'); |
} |
|
public function testGetAvailableVideoCodecs() |
{ |
$this->assertGreaterThan(0, count($this->getFormat()->getAvailableVideoCodecs())); |
} |
|
public function testCreateProgressListener() |
{ |
$media = $this->getMock('FFMpeg\Media\MediaTypeInterface'); |
$media->expects($this->any()) |
->method('getPathfile') |
->will($this->returnValue(__FILE__)); |
$format = $this->getFormat(); |
$ffprobe = $this->getFFProbeMock(); |
|
foreach ($format->createProgressListener($media, $ffprobe, 1, 3) as $listener) { |
$this->assertInstanceOf('FFMpeg\Format\ProgressListener\VideoProgressListener', $listener); |
$this->assertSame($ffprobe, $listener->getFFProbe()); |
$this->assertSame(__FILE__, $listener->getPathfile()); |
$this->assertSame(1, $listener->getCurrentPass()); |
$this->assertSame(3, $listener->getTotalPass()); |
} |
} |
|
public function testGetPasses() |
{ |
$this->assertInternalType('integer', $this->getFormat()->getPasses()); |
$this->assertGreaterThan(0, $this->getFormat()->getPasses()); |
} |
|
public function testGetModulus() |
{ |
$this->assertInternalType('integer', $this->getFormat()->getModulus()); |
$this->assertGreaterThan(0, $this->getFormat()->getModulus()); |
$this->assertEquals(0, $this->getFormat()->getModulus() % 2); |
} |
} |