diff --git a/src/FFMpeg/Format/DefaultFormat.php b/src/FFMpeg/Format/DefaultFormat.php index f763161..6f4ccdb 100644 --- a/src/FFMpeg/Format/DefaultFormat.php +++ b/src/FFMpeg/Format/DefaultFormat.php @@ -21,7 +21,7 @@ abstract class DefaultFormat implements Format public function getExtraParams() { - + return ''; } public function getWidth() @@ -133,6 +133,11 @@ abstract class DefaultFormat implements Format public function setGOPsize($GOPsize) { + if ($GOPsize < 1) + { + throw new \InvalidArgumentException('Wrong GOP size value'); + } + $this->GOPsize = (int) $GOPsize; } diff --git a/tests/src/FFMpeg/Format/DefaultFormatTest.php b/tests/src/FFMpeg/Format/DefaultFormatTest.php new file mode 100644 index 0000000..2426fe2 --- /dev/null +++ b/tests/src/FFMpeg/Format/DefaultFormatTest.php @@ -0,0 +1,314 @@ +object = new DefaultFormatTester(320, 240); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::__construct + * @covers FFMpeg\Format\DefaultFormat::getWidth + * @covers FFMpeg\Format\DefaultFormat::getHeight + */ + public function testConstruct() + { + $this->assertEquals(320, $this->object->getWidth()); + $this->assertEquals(240, $this->object->getHeight()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getExtraParams + */ + public function testGetExtraParams() + { + $this->assertEquals('-f format', $this->object->getExtraParams()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setDimensions + */ + public function testSetDimensions() + { + $this->object->setDimensions(240, 640); + $this->assertEquals(240, $this->object->getWidth()); + $this->assertEquals(640, $this->object->getHeight()); + + $this->object->setDimensions(242, 638); + $this->assertEquals(240, $this->object->getWidth()); + $this->assertEquals(640, $this->object->getHeight()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setDimensions + * @dataProvider getWrongDimensions + * @expectedException \InvalidArgumentException + */ + public function testWrongDimensions($width, $height) + { + $this->object->setDimensions($width, $height); + } + + /** + * Data provider for testWrongDimensions + * + * @return array + */ + public function getWrongDimensions() + { + return array( + array(0, 240), + array(240, 0), + array(-5, 240), + array(240, -5), + array(-5, -5), + array(0, 0) + ); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getFrameRate + */ + public function testGetFrameRate() + { + $this->assertEquals(25, $this->object->getFrameRate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setFrameRate + */ + public function testSetFrameRate() + { + $this->object->setFrameRate(12); + $this->assertEquals(12, $this->object->getFrameRate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setFrameRate + * @dataProvider getWrongFrameRates + * @expectedException \InvalidArgumentException + */ + public function testSetWrongFrameRates($framerate) + { + $this->object->setFrameRate($framerate); + } + + /** + * Data provider for testWrongFrameRates + * + * @return array + */ + public function getWrongFramerates() + { + return array(array(-5), array(0)); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getAudioCodec + */ + public function testGetAudioCodec() + { + $this->assertEquals('audiocodec1', $this->object->getAudioCodec()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setAudioCodec + */ + public function testSetAudioCodec() + { + $this->object->setAudioCodec('audiocodec2'); + $this->assertEquals('audiocodec2', $this->object->getAudioCodec()); + $this->object->setAudioCodec('audiocodec1'); + $this->assertEquals('audiocodec1', $this->object->getAudioCodec()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setAudioCodec + * @expectedException \InvalidArgumentException + */ + public function testSetWrongAudioCodec() + { + $this->object->setAudioCodec('audiocodec4'); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getAudioSampleRate + */ + public function testGetAudioSampleRate() + { + $this->assertEquals(44100, $this->object->getAudioSampleRate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setAudioSampleRate + */ + public function testSetAudioSampleRate() + { + $this->object->setAudioSampleRate(22050); + $this->assertEquals(22050, $this->object->getAudioSampleRate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setAudioSampleRate + * @expectedException \InvalidArgumentException + * @dataProvider getWrongAudioSampleRate + */ + public function testSetWrongAudioSampleRate($samplerate) + { + $this->object->setAudioSampleRate($samplerate); + } + + public function getWrongAudioSampleRate() + { + return array(array(-5), array(0)); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getVideoCodec + */ + public function testGetVideoCodec() + { + $this->assertEquals('videocodec2', $this->object->getVideoCodec()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setVideoCodec + */ + public function testSetVideoCodec() + { + $this->object->setVideoCodec('videocodec2'); + $this->assertEquals('videocodec2', $this->object->getVideoCodec()); + $this->object->setVideoCodec('videocodec1'); + $this->assertEquals('videocodec1', $this->object->getVideoCodec()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setVideoCodec + * @expectedException \InvalidArgumentException + */ + public function testSetWrongVideoCodec() + { + $this->object->setVideoCodec('videocodec4'); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getKiloBitrate + */ + public function testGetKiloBitrate() + { + $this->assertEquals(1000, $this->object->getKiloBitrate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setKiloBitrate + */ + public function testSetKiloBitrate() + { + $this->object->setKiloBitrate(500); + $this->assertEquals(500, $this->object->getKiloBitrate()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setKiloBitrate + * @dataProvider getWrongKiloBitrate + * @expectedException \InvalidArgumentException + */ + public function testSetWrongKiloBitrate($kbrate) + { + $this->object->setKiloBitrate($kbrate); + } + + public function getWrongKiloBitrate() + { + return array(array(-5), array(0)); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getGOPsize + */ + public function testGetGOPsize() + { + $this->assertEquals(25, $this->object->getGOPsize()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setGOPsize + */ + public function testSetGOPsize() + { + $this->object->setGOPsize(100); + $this->assertEquals(100, $this->object->getGOPsize()); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::setGOPsize + * @dataProvider getWrongGOPsize + * @expectedException \InvalidArgumentException + */ + public function testSetWrongGOPSize($GOP) + { + $this->object->setGOPsize($GOP); + } + + public function getWrongGOPsize() + { + return array(array(-5), array(0)); + } + + /** + * @covers FFMpeg\Format\DefaultFormat::getMultiple + */ + public function testGetMultiple() + { + $this->assertEquals(320, $this->object->getMultiple(321, 16)); + $this->assertEquals(320, $this->object->getMultiple(319, 16)); + $this->assertEquals(320, $this->object->getMultiple(313, 16)); + $this->assertEquals(304, $this->object->getMultiple(312, 16)); + $this->assertEquals(336, $this->object->getMultiple(329, 16)); + $this->assertEquals(16, $this->object->getMultiple(8, 16)); + } + +} + +class DefaultFormatTester extends DefaultFormat +{ + + protected $audioCodec = 'audiocodec1'; + protected $videoCodec = 'videocodec2'; + + protected function getAvailableAudioCodecs() + { + return array('audiocodec1', 'audiocodec2', 'audiocodec3'); + } + + protected function getAvailableVideoCodecs() + { + return array('videocodec1', 'videocodec2'); + } + + public function getExtraParams() + { + return '-f format'; + } + + public function getMultiple($value, $multiple) + { + return parent::getMultiple($value, $multiple); + } + +}