Version 0.3

This commit is contained in:
Romain Neutron 2013-06-25 10:03:20 +02:00
commit ad3a5af623
130 changed files with 7283 additions and 2627 deletions

View file

@ -0,0 +1,56 @@
<?php
namespace FFMpeg\Tests\FFProbe\DataMapping;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\DataMapping\AbstractData;
class AbstractDataTest extends TestCase
{
public function testHas()
{
$imp = new Implementation(array('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(array('key1' => 'value1', 'key2' => 'value2'));
$this->assertEquals('value1', $imp->get('key1'));
$this->assertEquals('value2', $imp->get('key2'));
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testGetInvalid()
{
$imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2'));
$imp->get('key3');
}
public function testKeys()
{
$imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2'));
$this->assertEquals(array('key1', 'key2'), $imp->keys());
}
public function testAll()
{
$values = array('key1' => 'value1', 'key2' => 'value2');
$imp = new Implementation($values);
$this->assertEquals($values, $imp->all());
}
}
class Implementation extends AbstractData
{
}

View file

@ -0,0 +1,89 @@
<?php
namespace FFMpeg\Tests\FFProbe\DataMapping;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\DataMapping\StreamCollection;
class StreamCollectionTest extends TestCase
{
public function testAdd()
{
$stream = $this->getStreamMock();
$collection = new StreamCollection();
$this->assertEquals(array(), $collection->all());
$collection->add($stream);
$this->assertEquals(array($stream), $collection->all());
$collection->add($stream);
$this->assertEquals(array($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(array($audio, $video));
$videos = $collection->videos();
$this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $videos);
$this->assertCount(1, $videos);
$this->assertEquals(array($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(array($audio, $video));
$audios = $collection->audios();
$this->assertInstanceOf('FFMpeg\FFProbe\DataMapping\StreamCollection', $audios);
$this->assertCount(1, $audios);
$this->assertEquals(array($audio), $audios->all());
}
public function testCount()
{
$stream = $this->getStreamMock();
$collection = new StreamCollection(array($stream));
$this->assertCount(1, $collection);
}
public function testGetIterator()
{
$audio = $this->getStreamMock();
$video = $this->getStreamMock();
$collection = new StreamCollection(array($audio, $video));
$this->assertInstanceOf('\Iterator', $collection->getIterator());
$this->assertCount(2, $collection->getIterator());
}
public function testFirst()
{
$stream1 = $this->getStreamMock();
$stream2 = $this->getStreamMock();
$coll = new StreamCollection(array($stream1, $stream2));
$this->assertSame($stream1, $coll->first());
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace FFMpeg\Tests\FFProbe\DataMapping;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\DataMapping\Stream;
class StreamTest extends TestCase
{
/**
* @dataProvider provideAudioCases
*/
public function testIsAudio($isAudio, $properties)
{
$stream = new Stream($properties);
$this->assertTrue($isAudio === $stream->isAudio());
}
public function provideAudioCases()
{
return array(
array(true, array('codec_type' => 'audio')),
array(false, array('codec_type' => 'video')),
);
}
/**
* @dataProvider provideVideoCases
*/
public function testIsVideo($isVideo, $properties)
{
$stream = new Stream($properties);
$this->assertTrue($isVideo === $stream->isVideo());
}
public function provideVideoCases()
{
return array(
array(true, array('codec_type' => 'video')),
array(false, array('codec_type' => 'audio')),
);
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace FFMpeg\Tests\FFProbe;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\Mapper;
use FFMpeg\FFProbe;
use FFMpeg\FFProbe\DataMapping\Format;
use FFMpeg\FFProbe\DataMapping\Stream;
use FFMpeg\FFProbe\DataMapping\StreamCollection;
class MapperTest extends TestCase
{
/**
* @dataProvider provideMappings
*/
public function testMap($type, $data, $expected)
{
$mapper = new Mapper();
$this->assertEquals($expected, $mapper->map($type, $data));
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testMapInvalidArgument()
{
$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 array(
array(FFProbe::TYPE_FORMAT, $format, new Format($format['format'])),
array(FFProbe::TYPE_STREAMS, $streams, new StreamCollection(array_map(function ($streamData) {
return new Stream($streamData);
}, $streams['streams']))),
);
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace FFMpeg\Tests\FFProbe;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\OptionsTester;
class OptionsTesterTest extends TestCase
{
/**
* @dataProvider provideOptions
*/
public function testHasOptionWithCacheEmpty($isPresent, $data, $optionName)
{
$cache = $this->getCacheMock();
$cache->expects($this->never())
->method('fetch');
$cache->expects($this->exactly(2))
->method('contains')
->will($this->returnValue(false));
$cache->expects($this->exactly(2))
->method('save');
$ffprobe = $this->getFFProbeDriverMock();
$ffprobe->expects($this->once())
->method('command')
->with(array('-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 array(
array(true, $data, '-print_format'),
array(false, $data, '-another_print_format'),
);
}
/**
* @dataProvider provideOptions
*/
public function testHasOptionWithHelpCacheLoaded($isPresent, $data, $optionName)
{
$cache = $this->getCacheMock();
$cache->expects($this->once())
->method('fetch')
->will($this->returnValue($data));
$cache->expects($this->at(0))
->method('contains')
->will($this->returnValue(false));
$cache->expects($this->at(1))
->method('contains')
->will($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();
$cache->expects($this->once())
->method('fetch')
->with('option-' . $optionName)
->will($this->returnValue($isPresent));
$cache->expects($this->once())
->method('contains')
->with('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));
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace FFMpeg\Tests\FFProbe;
use FFMpeg\Tests\TestCase;
use FFMpeg\FFProbe\OutputParser;
use FFMpeg\FFProbe;
class OutputParserTest extends TestCase
{
/**
* @dataProvider provideTypeDataAndOutput
*/
public function testParse($type, $data, $expectedOutput)
{
$parser = new OutputParser();
$this->assertEquals($expectedOutput, $parser->parse($type, $data));
}
/**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/
public function testParseWithInvalidArgument()
{
$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 array(
array(FFProbe::TYPE_FORMAT, $rawFormat, $expectedFormat),
array(FFProbe::TYPE_STREAMS, $rawStreams, $expectedStreams),
);
}
}