[BC] Upgraded dependencies, dropped support for anything below PHP 8.0. (#849)
* GitHub actions + style fixes + updated packages * Fixed workflows dir * Support for PHP 8.1 (#1) * Update README.md * Revert some changes from upstream
This commit is contained in:
parent
72c946dc7d
commit
111c153428
335 changed files with 4394 additions and 28116 deletions
52
tests/FFMpeg/Unit/FFProbe/DataMapping/AbstractDataTest.php
Normal file
52
tests/FFMpeg/Unit/FFProbe/DataMapping/AbstractDataTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe\DataMapping;
|
||||
|
||||
use FFMpeg\FFProbe\DataMapping\AbstractData;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class AbstractDataTest extends TestCase
|
||||
{
|
||||
public function testHas()
|
||||
{
|
||||
$imp = new Implementation(['key1' => 'value1', 'key2' => 'value2']);
|
||||
|
||||
$this->assertTrue($imp->has('key1'));
|
||||
$this->assertTrue($imp->has('key2'));
|
||||
$this->assertFalse($imp->has('value1'));
|
||||
$this->assertFalse($imp->has('key3'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$imp = new Implementation(['key1' => 'value1', 'key2' => 'value2']);
|
||||
|
||||
$this->assertEquals('value1', $imp->get('key1'));
|
||||
$this->assertEquals('value2', $imp->get('key2'));
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$imp = new Implementation(['key1' => 'value1', 'key2' => 'value2']);
|
||||
$this->assertSame('yololo', $imp->get('key3', 'yololo'));
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$imp = new Implementation(['key1' => 'value1', 'key2' => 'value2']);
|
||||
|
||||
$this->assertEquals(['key1', 'key2'], $imp->keys());
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$values = ['key1' => 'value1', 'key2' => 'value2'];
|
||||
$imp = new Implementation($values);
|
||||
|
||||
$this->assertEquals($values, $imp->all());
|
||||
}
|
||||
}
|
||||
|
||||
class Implementation extends AbstractData
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe\DataMapping;
|
||||
|
||||
use FFMpeg\FFProbe\DataMapping\StreamCollection;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class StreamCollectionTest extends TestCase
|
||||
{
|
||||
public function testAdd()
|
||||
{
|
||||
$stream = $this->getStreamMock();
|
||||
|
||||
$collection = new StreamCollection();
|
||||
$this->assertEquals([], $collection->all());
|
||||
$collection->add($stream);
|
||||
$this->assertEquals([$stream], $collection->all());
|
||||
$collection->add($stream);
|
||||
$this->assertEquals([$stream, $stream], $collection->all());
|
||||
}
|
||||
|
||||
public function testVideos()
|
||||
{
|
||||
$audio = $this->getStreamMock();
|
||||
$audio->expects($this->once())
|
||||
->method('isVideo')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$video = $this->getStreamMock();
|
||||
$video->expects($this->once())
|
||||
->method('isVideo')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$collection = new StreamCollection([$audio, $video]);
|
||||
$videos = $collection->videos();
|
||||
|
||||
$this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $videos);
|
||||
$this->assertCount(1, $videos);
|
||||
$this->assertEquals([$video], $videos->all());
|
||||
}
|
||||
|
||||
public function testAudios()
|
||||
{
|
||||
$audio = $this->getStreamMock();
|
||||
$audio->expects($this->once())
|
||||
->method('isAudio')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$video = $this->getStreamMock();
|
||||
$video->expects($this->once())
|
||||
->method('isAudio')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$collection = new StreamCollection([$audio, $video]);
|
||||
$audios = $collection->audios();
|
||||
|
||||
$this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $audios);
|
||||
$this->assertCount(1, $audios);
|
||||
$this->assertEquals([$audio], $audios->all());
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$stream = $this->getStreamMock();
|
||||
|
||||
$collection = new StreamCollection([$stream]);
|
||||
$this->assertCount(1, $collection);
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$audio = $this->getStreamMock();
|
||||
$video = $this->getStreamMock();
|
||||
|
||||
$collection = new StreamCollection([$audio, $video]);
|
||||
$this->assertInstanceOf('\Iterator', $collection->getIterator());
|
||||
$this->assertCount(2, $collection->getIterator());
|
||||
}
|
||||
|
||||
public function testFirst()
|
||||
{
|
||||
$stream1 = $this->getStreamMock();
|
||||
$stream2 = $this->getStreamMock();
|
||||
|
||||
$coll = new StreamCollection([$stream1, $stream2]);
|
||||
|
||||
$this->assertSame($stream1, $coll->first());
|
||||
}
|
||||
}
|
||||
136
tests/FFMpeg/Unit/FFProbe/DataMapping/StreamTest.php
Normal file
136
tests/FFMpeg/Unit/FFProbe/DataMapping/StreamTest.php
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe\DataMapping;
|
||||
|
||||
use FFMpeg\Coordinate\Dimension;
|
||||
use FFMpeg\FFProbe\DataMapping\Stream;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class StreamTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideAudioCases
|
||||
*/
|
||||
public function testIsAudio($isAudio, $properties)
|
||||
{
|
||||
$stream = new Stream($properties);
|
||||
$this->assertTrue($isAudio === $stream->isAudio());
|
||||
}
|
||||
|
||||
public function provideAudioCases()
|
||||
{
|
||||
return [
|
||||
[true, ['codec_type' => 'audio']],
|
||||
[false, ['codec_type' => 'video']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideVideoCases
|
||||
*/
|
||||
public function testIsVideo($isVideo, $properties)
|
||||
{
|
||||
$stream = new Stream($properties);
|
||||
$this->assertTrue($isVideo === $stream->isVideo());
|
||||
}
|
||||
|
||||
public function provideVideoCases()
|
||||
{
|
||||
return [
|
||||
[true, ['codec_type' => 'video']],
|
||||
[false, ['codec_type' => 'audio']],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetDimensionsFromAudio()
|
||||
{
|
||||
$this->expectException(
|
||||
'\FFMpeg\Exception\LogicException',
|
||||
'Dimensions can only be retrieved from video streams.'
|
||||
);
|
||||
$stream = new Stream(['codec_type' => 'audio']);
|
||||
$stream->getDimensions();
|
||||
}
|
||||
|
||||
public function testGetDimensionsFromVideo()
|
||||
{
|
||||
$stream = new Stream(['codec_type' => 'video', 'width' => 960, 'height' => 720]);
|
||||
$this->assertEquals(new Dimension(960, 720), $stream->getDimensions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidPropertiesForDimensionsExtraction
|
||||
*/
|
||||
public function testUnableToGetDimensionsFromVideo($properties)
|
||||
{
|
||||
$this->expectException(
|
||||
'\FFMpeg\Exception\RuntimeException',
|
||||
'Unable to extract dimensions.'
|
||||
);
|
||||
$stream = new Stream(['codec_type' => 'video', 'width' => 960]);
|
||||
$stream->getDimensions();
|
||||
}
|
||||
|
||||
public function provideInvalidPropertiesForDimensionsExtraction()
|
||||
{
|
||||
return [
|
||||
['codec_type' => 'video', 'width' => 960],
|
||||
['codec_type' => 'video', 'height' => 960],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePropertiesForDimensionsExtraction
|
||||
*/
|
||||
public function testGetDimensionsFromVideoWithDisplayRatio($data)
|
||||
{
|
||||
$stream = new Stream([
|
||||
'codec_type' => 'video',
|
||||
'width' => $data['width'],
|
||||
'height' => $data['height'],
|
||||
'sample_aspect_ratio' => $data['sar'],
|
||||
'display_aspect_ratio' => $data['dar'],
|
||||
]);
|
||||
$this->assertEquals(new Dimension($data['result_width'], $data['result_height']), $stream->getDimensions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidRatios
|
||||
*/
|
||||
public function testGetDimensionsFromVideoWithInvalidDisplayRatio($invalidRatio)
|
||||
{
|
||||
$stream = new Stream(['codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => $invalidRatio, 'display_aspect_ratio' => '16:9']);
|
||||
$this->assertEquals(new Dimension(960, 720), $stream->getDimensions());
|
||||
}
|
||||
|
||||
public function provideInvalidRatios()
|
||||
{
|
||||
return [['0:1'], ['2:1:3']];
|
||||
}
|
||||
|
||||
public function providePropertiesForDimensionsExtraction()
|
||||
{
|
||||
return [
|
||||
[
|
||||
['width' => '960', 'height' => '720',
|
||||
'sar' => '4:3', 'dar' => '16:9',
|
||||
'result_width' => '1280', 'result_height' => '720', ],
|
||||
],
|
||||
[
|
||||
['width' => '1920', 'height' => '1080',
|
||||
'sar' => '1:1', 'dar' => '16:9',
|
||||
'result_width' => '1920', 'result_height' => '1080', ],
|
||||
],
|
||||
[
|
||||
['width' => '640', 'height' => '480',
|
||||
'sar' => '75:74', 'dar' => '50:37',
|
||||
'result_width' => '649', 'result_height' => '480', ],
|
||||
],
|
||||
[
|
||||
['width' => '720', 'height' => '576',
|
||||
'sar' => '52:28', 'dar' => '16:9',
|
||||
'result_width' => '1337', 'result_height' => '752', ],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
42
tests/FFMpeg/Unit/FFProbe/MapperTest.php
Normal file
42
tests/FFMpeg/Unit/FFProbe/MapperTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe;
|
||||
|
||||
use FFMpeg\FFProbe;
|
||||
use FFMpeg\FFProbe\DataMapping\Format;
|
||||
use FFMpeg\FFProbe\DataMapping\Stream;
|
||||
use FFMpeg\FFProbe\DataMapping\StreamCollection;
|
||||
use FFMpeg\FFProbe\Mapper;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class MapperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideMappings
|
||||
*/
|
||||
public function testMap($type, $data, $expected)
|
||||
{
|
||||
$mapper = new Mapper();
|
||||
$this->assertEquals($expected, $mapper->map($type, $data));
|
||||
}
|
||||
|
||||
public function testMapInvalidArgument()
|
||||
{
|
||||
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
|
||||
$mapper = new Mapper();
|
||||
$mapper->map('cool type', 'data');
|
||||
}
|
||||
|
||||
public function provideMappings()
|
||||
{
|
||||
$format = json_decode(file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_format.json'), true);
|
||||
$streams = json_decode(file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_streams.json'), true);
|
||||
|
||||
return [
|
||||
[FFProbe::TYPE_FORMAT, $format, new Format($format['format'])],
|
||||
[FFProbe::TYPE_STREAMS, $streams, new StreamCollection(array_map(function ($streamData) {
|
||||
return new Stream($streamData);
|
||||
}, $streams['streams']))],
|
||||
];
|
||||
}
|
||||
}
|
||||
132
tests/FFMpeg/Unit/FFProbe/OptionsTesterTest.php
Normal file
132
tests/FFMpeg/Unit/FFProbe/OptionsTesterTest.php
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe;
|
||||
|
||||
use FFMpeg\FFProbe\OptionsTester;
|
||||
use Symfony\Component\Cache\CacheItem;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class OptionsTesterTest extends TestCase
|
||||
{
|
||||
public function testHasOptionWithOldFFProbe()
|
||||
{
|
||||
$this->expectException(
|
||||
'\FFMpeg\Exception\RuntimeException',
|
||||
'Your FFProbe version is too old and does not support `-help` option, please upgrade.'
|
||||
);
|
||||
$cache = $this->getCacheMock();
|
||||
|
||||
$executionFailerExceptionMock = $this->getMockBuilder('Alchemy\BinaryDriver\Exception\ExecutionFailureException')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$ffprobe = $this->getFFProbeDriverMock();
|
||||
$ffprobe->expects($this->once())
|
||||
->method('command')
|
||||
->with(['-help', '-loglevel', 'quiet'])
|
||||
->will($this->throwException($executionFailerExceptionMock));
|
||||
|
||||
$tester = new OptionsTester($ffprobe, $cache);
|
||||
$tester->has('-print_format');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideOptions
|
||||
*/
|
||||
public function testHasOptionWithCacheEmpty($isPresent, $data, $optionName)
|
||||
{
|
||||
$cache = $this->getCacheMock();
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('getItem')
|
||||
->will($this->returnValue(new CacheItem));
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('hasItem')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('save');
|
||||
|
||||
$ffprobe = $this->getFFProbeDriverMock();
|
||||
$ffprobe->expects($this->once())
|
||||
->method('command')
|
||||
->with(['-help', '-loglevel', 'quiet'])
|
||||
->will($this->returnValue($data));
|
||||
|
||||
$tester = new OptionsTester($ffprobe, $cache);
|
||||
$this->assertTrue($isPresent === $tester->has($optionName));
|
||||
}
|
||||
|
||||
public function provideOptions()
|
||||
{
|
||||
$data = file_get_contents(__DIR__ . '/../../fixtures/ffprobe/help.raw');
|
||||
|
||||
return [
|
||||
[true, $data, '-print_format'],
|
||||
[false, $data, '-another_print_format'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideOptions
|
||||
*/
|
||||
public function testHasOptionWithHelpCacheLoaded($isPresent, $data, $optionName)
|
||||
{
|
||||
$cache = $this->getCacheMock();
|
||||
|
||||
$cacheItem = new CacheItem;
|
||||
$cacheItem->set($data);
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('getItem')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnValue($cacheItem),
|
||||
$this->returnValue(new CacheItem)
|
||||
);
|
||||
|
||||
$cache->expects($this->exactly(2))
|
||||
->method('hasItem')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnValue(false),
|
||||
$this->returnValue(true)
|
||||
);
|
||||
$cache->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$ffprobe = $this->getFFProbeDriverMock();
|
||||
$ffprobe->expects($this->never())
|
||||
->method('command');
|
||||
|
||||
$tester = new OptionsTester($ffprobe, $cache);
|
||||
$this->assertTrue($isPresent === $tester->has($optionName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideOptions
|
||||
*/
|
||||
public function testHasOptionWithCacheFullyLoaded($isPresent, $data, $optionName)
|
||||
{
|
||||
$cache = $this->getCacheMock();
|
||||
|
||||
$cacheItem = new CacheItem();
|
||||
$cacheItem->set($isPresent);
|
||||
|
||||
$cache->expects($this->once())
|
||||
->method('getItem')
|
||||
->with(md5('option-' . $optionName))
|
||||
->will($this->returnValue($cacheItem));
|
||||
|
||||
$cache->expects($this->once())
|
||||
->method('hasItem')
|
||||
->with(md5('option-' . $optionName))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$ffprobe = $this->getFFProbeDriverMock();
|
||||
$ffprobe->expects($this->never())
|
||||
->method('command');
|
||||
|
||||
$tester = new OptionsTester($ffprobe, $cache);
|
||||
$this->assertTrue($isPresent === $tester->has($optionName));
|
||||
}
|
||||
}
|
||||
40
tests/FFMpeg/Unit/FFProbe/OutputParserTest.php
Normal file
40
tests/FFMpeg/Unit/FFProbe/OutputParserTest.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\FFMpeg\Unit\FFProbe;
|
||||
|
||||
use FFMpeg\FFProbe;
|
||||
use FFMpeg\FFProbe\OutputParser;
|
||||
use Tests\FFMpeg\Unit\TestCase;
|
||||
|
||||
class OutputParserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideTypeDataAndOutput
|
||||
*/
|
||||
public function testParse($type, $data, $expectedOutput)
|
||||
{
|
||||
$parser = new OutputParser();
|
||||
$this->assertEquals($expectedOutput, $parser->parse($type, $data));
|
||||
}
|
||||
|
||||
public function testParseWithInvalidArgument()
|
||||
{
|
||||
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
|
||||
$parser = new OutputParser();
|
||||
$parser->parse('comme ca', 'data');
|
||||
}
|
||||
|
||||
public function provideTypeDataAndOutput()
|
||||
{
|
||||
$expectedFormat = json_decode(file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_format.json'), true);
|
||||
$expectedStreams = json_decode(file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_streams.json'), true);
|
||||
|
||||
$rawFormat = file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_format.raw');
|
||||
$rawStreams = file_get_contents(__DIR__.'/../../fixtures/ffprobe/show_streams.raw');
|
||||
|
||||
return [
|
||||
[FFProbe::TYPE_FORMAT, $rawFormat, $expectedFormat],
|
||||
[FFProbe::TYPE_STREAMS, $rawStreams, $expectedStreams],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue