Fix PhpUnit tests for newer php version

This commit is contained in:
Alexander Schranz 2020-02-13 00:39:31 +01:00
commit 14dc6a8b1b
21 changed files with 48 additions and 40 deletions

1
.gitignore vendored
View file

@ -5,5 +5,6 @@ composer.phar
composer.lock composer.lock
phpunit.xml phpunit.xml
.phpunit.result.cache .phpunit.result.cache
/tests/Functional/output/output-*
sami.phar sami.phar
.idea/ .idea/

View file

@ -94,7 +94,7 @@ class Concat extends AbstractMediaType
$fileStream = @fopen($sourcesFile, 'w'); $fileStream = @fopen($sourcesFile, 'w');
if($fileStream === false) { if($fileStream === false) {
throw new ExecutionFailureException('Cannot open the temporary file.'); throw new RuntimeException('Cannot open the temporary file.');
} }
$count_videos = 0; $count_videos = 0;

View file

@ -71,10 +71,10 @@ class VideoTranscodeTest extends FunctionalTestCase
} }
/** /**
* @expectedException \FFMpeg\Exception\RuntimeException
*/ */
public function testTranscodeInvalidFile() public function testTranscodeInvalidFile()
{ {
$this->expectException('\FFMpeg\Exception\RuntimeException');
$ffmpeg = $this->getFFMpeg(); $ffmpeg = $this->getFFMpeg();
$ffmpeg->open(__DIR__ . '/../files/UnknownFileTest.ogv'); $ffmpeg->open(__DIR__ . '/../files/UnknownFileTest.ogv');
} }
@ -84,7 +84,7 @@ class VideoTranscodeTest extends FunctionalTestCase
$ffmpeg = $this->getFFMpeg(); $ffmpeg = $this->getFFMpeg();
$video = new Video(__DIR__ . '/../files/UnknownFileTest.ogv', $ffmpeg->getFFMpegDriver(), $ffmpeg->getFFProbe()); $video = new Video(__DIR__ . '/../files/UnknownFileTest.ogv', $ffmpeg->getFFMpegDriver(), $ffmpeg->getFFProbe());
$this->setExpectedException('FFMpeg\Exception\RuntimeException'); $this->expectException('\FFMpeg\Exception\RuntimeException');
$video->save(new X264('aac'), __DIR__ . '/output/output-x264.mp4'); $video->save(new X264('aac'), __DIR__ . '/output/output-x264.mp4');
} }

View file

@ -9,10 +9,10 @@ class DimensionTest extends TestCase
{ {
/** /**
* @dataProvider provideInvalidDimensions * @dataProvider provideInvalidDimensions
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testInvalidDimensions($width, $height) public function testInvalidDimensions($width, $height)
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
new Dimension($width, $height); new Dimension($width, $height);
} }

View file

@ -15,10 +15,10 @@ class FrameRateTest extends TestCase
/** /**
* @dataProvider provideInvalidFrameRates * @dataProvider provideInvalidFrameRates
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testInvalidFrameRate($value) public function testInvalidFrameRate($value)
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
new FrameRate($value); new FrameRate($value);
} }

View file

@ -29,10 +29,10 @@ class TimeCodeTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testFromInvalidString() public function testFromInvalidString()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
TimeCode::fromString('lalali lala'); TimeCode::fromString('lalali lala');
} }

View file

@ -42,10 +42,10 @@ class FFMpegDriverTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\ExecutableNotFoundException
*/ */
public function testCreateFailureThrowsAnException() public function testCreateFailureThrowsAnException()
{ {
$this->expectException('\FFMpeg\Exception\ExecutableNotFoundException');
FFMpegDriver::create($this->getLoggerMock(), array('ffmpeg.binaries' => '/path/to/nowhere')); FFMpegDriver::create($this->getLoggerMock(), array('ffmpeg.binaries' => '/path/to/nowhere'));
} }
} }

View file

@ -42,10 +42,10 @@ class FFProbeDriverTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\ExecutableNotFoundException
*/ */
public function testCreateFailureThrowsAnException() public function testCreateFailureThrowsAnException()
{ {
$this->expectException('\FFMpeg\Exception\ExecutableNotFoundException');
FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere')); FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere'));
} }
} }

View file

@ -51,7 +51,7 @@ class FFMpegServiceProviderTest extends BaseTestCase
) )
)); ));
$this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFMpeg'); $this->expectException('\FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFMpeg');
$app['ffmpeg']; $app['ffmpeg'];
} }
@ -64,7 +64,7 @@ class FFMpegServiceProviderTest extends BaseTestCase
) )
)); ));
$this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFProbe'); $this->expectException('\FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFProbe');
$app['ffmpeg.ffprobe']; $app['ffmpeg.ffprobe'];
} }
} }

View file

@ -9,11 +9,11 @@ use FFMpeg\FFProbe\DataMapping\Stream;
class FFMpegTest extends TestCase class FFMpegTest extends TestCase
{ {
/** /**
* @expectedException \FFMpeg\Exception\RuntimeException
* @expectedExceptionMessage Unable to probe "/path/to/unknown/file". * @expectedExceptionMessage Unable to probe "/path/to/unknown/file".
*/ */
public function testOpenInvalid() public function testOpenInvalid()
{ {
$this->expectException('\FFMpeg\Exception\RuntimeException');
$ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $this->getFFProbeMock()); $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $this->getFFProbeMock());
$ffmpeg->open('/path/to/unknown/file'); $ffmpeg->open('/path/to/unknown/file');
} }
@ -58,10 +58,10 @@ class FFMpegTest extends TestCase
} }
/** /**
* @expectedException \FFMpeg\Exception\InvalidArgumentException
*/ */
public function testOpenUnknown() public function testOpenUnknown()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$ffprobe = $this->getFFProbeMock(); $ffprobe = $this->getFFProbeMock();
$ffprobe->expects($this->once()) $ffprobe->expects($this->once())
->method('streams') ->method('streams')

View file

@ -43,11 +43,11 @@ class StreamTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\LogicException
* @expectedExceptionMessage Dimensions can only be retrieved from video streams. * @expectedExceptionMessage Dimensions can only be retrieved from video streams.
*/ */
public function testGetDimensionsFromAudio() public function testGetDimensionsFromAudio()
{ {
$this->expectException('\FFMpeg\Exception\LogicException');
$stream = new Stream(array('codec_type' => 'audio')); $stream = new Stream(array('codec_type' => 'audio'));
$stream->getDimensions(); $stream->getDimensions();
} }
@ -60,11 +60,11 @@ class StreamTest extends TestCase
/** /**
* @dataProvider provideInvalidPropertiesForDimensionsExtraction * @dataProvider provideInvalidPropertiesForDimensionsExtraction
* @expectedException FFMpeg\Exception\RuntimeException
* @expectedExceptionMessage Unable to extract dimensions. * @expectedExceptionMessage Unable to extract dimensions.
*/ */
public function testUnableToGetDimensionsFromVideo($properties) public function testUnableToGetDimensionsFromVideo($properties)
{ {
$this->expectException('\FFMpeg\Exception\RuntimeException');
$stream = new Stream(array('codec_type' => 'video', 'width' => 960)); $stream = new Stream(array('codec_type' => 'video', 'width' => 960));
$stream->getDimensions(); $stream->getDimensions();
} }

View file

@ -21,10 +21,10 @@ class MapperTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testMapInvalidArgument() public function testMapInvalidArgument()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$mapper = new Mapper(); $mapper = new Mapper();
$mapper->map('cool type', 'data'); $mapper->map('cool type', 'data');
} }

View file

@ -3,24 +3,25 @@
namespace Tests\FFMpeg\Unit\FFProbe; namespace Tests\FFMpeg\Unit\FFProbe;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Exception\RuntimeException;
use Tests\FFMpeg\Unit\TestCase; use Tests\FFMpeg\Unit\TestCase;
use FFMpeg\FFProbe\OptionsTester; use FFMpeg\FFProbe\OptionsTester;
class OptionsTesterTest extends TestCase class OptionsTesterTest extends TestCase
{ {
/** /**
* @expectedException FFMpeg\Exception\RuntimeException
* @expectedExceptionMessage Your FFProbe version is too old and does not support `-help` option, please upgrade. * @expectedExceptionMessage Your FFProbe version is too old and does not support `-help` option, please upgrade.
*/ */
public function testHasOptionWithOldFFProbe() public function testHasOptionWithOldFFProbe()
{ {
$this->expectException('\FFMpeg\Exception\RuntimeException');
$cache = $this->getCacheMock(); $cache = $this->getCacheMock();
$ffprobe = $this->getFFProbeDriverMock(); $ffprobe = $this->getFFProbeDriverMock();
$ffprobe->expects($this->once()) $ffprobe->expects($this->once())
->method('command') ->method('command')
->with(array('-help', '-loglevel', 'quiet')) ->with(array('-help', '-loglevel', 'quiet'))
->will($this->throwException(new ExecutionFailureException('Failed to execute'))); ->will($this->throwException(new RuntimeException('Failed to execute')));
$tester = new OptionsTester($ffprobe, $cache); $tester = new OptionsTester($ffprobe, $cache);
$tester->has('-print_format'); $tester->has('-print_format');

View file

@ -18,10 +18,10 @@ class OutputParserTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testParseWithInvalidArgument() public function testParseWithInvalidArgument()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$parser = new OutputParser(); $parser = new OutputParser();
$parser->parse('comme ca', 'data'); $parser->parse('comme ca', 'data');
} }

View file

@ -236,11 +236,11 @@ class FFProbeTest extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\RuntimeException
* @dataProvider provideProbeMethod * @dataProvider provideProbeMethod
*/ */
public function testProbeWithoutShowStreamsAvailable($method) public function testProbeWithoutShowStreamsAvailable($method)
{ {
$this->expectException('\FFMpeg\Exception\RuntimeException');
$pathfile = __FILE__; $pathfile = __FILE__;
$ffprobe = new FFProbe($this->getFFProbeDriverMock(), $this->getCacheMock()); $ffprobe = new FFProbe($this->getFFProbeDriverMock(), $this->getCacheMock());

View file

@ -65,9 +65,9 @@ class ExtractMultipleFramesFilterTest extends TestCase
} }
/** /**
* @expectedException \FFMpeg\Exception\InvalidArgumentException
*/ */
public function testInvalidFrameFileType() { public function testInvalidFrameFileType() {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$filter = new ExtractMultipleFramesFilter('1/1', '/'); $filter = new ExtractMultipleFramesFilter('1/1', '/');
$filter->setFrameFileType('webm'); $filter->setFrameFileType('webm');
} }

View file

@ -62,11 +62,11 @@ class RotateFilterTest extends TestCase
} }
/** /**
* @expectedException \FFMpeg\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid angle value. * @expectedExceptionMessage Invalid angle value.
*/ */
public function testApplyInvalidAngle() public function testApplyInvalidAngle()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
new RotateFilter('90'); new RotateFilter('90');
} }
} }

View file

@ -9,7 +9,11 @@ abstract class AudioTestCase extends TestCase
{ {
public function testExtraParams() public function testExtraParams()
{ {
foreach ($this->getFormat()->getExtraParams() as $param) { $extraParams = $this->getFormat()->getExtraParams();
$this->assertIsArray($extraParams);
foreach ($extraParams as $param) {
$this->assertScalar($param); $this->assertScalar($param);
} }
} }
@ -31,10 +35,10 @@ abstract class AudioTestCase extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetInvalidAudioCodec() public function testSetInvalidAudioCodec()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioCodec('invalid-random-audio-codec'); $this->getFormat()->setAudioCodec('invalid-random-audio-codec');
} }
@ -45,7 +49,7 @@ abstract class AudioTestCase extends TestCase
public function testGetAudioKiloBitrate() public function testGetAudioKiloBitrate()
{ {
$this->assertInternalType('integer', $this->getFormat()->getAudioKiloBitrate()); $this->assertIsInt($this->getFormat()->getAudioKiloBitrate());
} }
public function testSetAudioKiloBitrate() public function testSetAudioKiloBitrate()
@ -56,24 +60,24 @@ abstract class AudioTestCase extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetInvalidKiloBitrate() public function testSetInvalidKiloBitrate()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioKiloBitrate(0); $this->getFormat()->setAudioKiloBitrate(0);
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetNegativeKiloBitrate() public function testSetNegativeKiloBitrate()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioKiloBitrate(-10); $this->getFormat()->setAudioKiloBitrate(-10);
} }
public function testGetAudioChannels() public function testGetAudioChannels()
{ {
$this->assertInternalType('null', $this->getFormat()->getAudioChannels()); $this->assertNull($this->getFormat()->getAudioChannels());
} }
public function testSetAudioChannels() public function testSetAudioChannels()
@ -84,18 +88,18 @@ abstract class AudioTestCase extends TestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetInvalidChannels() public function testSetInvalidChannels()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioChannels(0); $this->getFormat()->setAudioChannels(0);
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetNegativeChannels() public function testSetNegativeChannels()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioChannels(-10); $this->getFormat()->setAudioChannels(-10);
} }

View file

@ -14,7 +14,7 @@ abstract class VideoTestCase extends AudioTestCase
public function testSupportBFrames() public function testSupportBFrames()
{ {
$this->assertInternalType('boolean', $this->getFormat()->supportBFrames()); $this->assertIsBool($this->getFormat()->supportBFrames());
} }
public function testSetVideoCodec() public function testSetVideoCodec()
@ -29,7 +29,7 @@ abstract class VideoTestCase extends AudioTestCase
public function testGetKiloBitrate() public function testGetKiloBitrate()
{ {
$this->assertInternalType('integer', $this->getFormat()->getKiloBitrate()); $this->assertIsInt($this->getFormat()->getKiloBitrate());
} }
public function testSetKiloBitrate() public function testSetKiloBitrate()
@ -40,10 +40,10 @@ abstract class VideoTestCase extends AudioTestCase
} }
/** /**
* @expectedException FFMpeg\Exception\InvalidArgumentException
*/ */
public function testSetInvalidVideoCodec() public function testSetInvalidVideoCodec()
{ {
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setVideoCodec('invalid-random-video-codec'); $this->getFormat()->setVideoCodec('invalid-random-video-codec');
} }
@ -72,13 +72,13 @@ abstract class VideoTestCase extends AudioTestCase
public function testGetPasses() public function testGetPasses()
{ {
$this->assertInternalType('integer', $this->getFormat()->getPasses()); $this->assertIsInt($this->getFormat()->getPasses());
$this->assertGreaterThan(0, $this->getFormat()->getPasses()); $this->assertGreaterThan(0, $this->getFormat()->getPasses());
} }
public function testGetModulus() public function testGetModulus()
{ {
$this->assertInternalType('integer', $this->getFormat()->getModulus()); $this->assertIsInt($this->getFormat()->getModulus());
$this->assertGreaterThan(0, $this->getFormat()->getModulus()); $this->assertGreaterThan(0, $this->getFormat()->getModulus());
$this->assertEquals(0, $this->getFormat()->getModulus() % 2); $this->assertEquals(0, $this->getFormat()->getModulus() % 2);
} }

View file

@ -2,6 +2,7 @@
namespace Tests\FFMpeg\Unit\Media; namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Audio; use FFMpeg\Media\Audio;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Format\AudioInterface; use FFMpeg\Format\AudioInterface;
@ -55,7 +56,7 @@ class AudioTest extends AbstractStreamableTestCase
$filters->expects($this->never()) $filters->expects($this->never())
->method('add'); ->method('add');
$this->setExpectedException('FFMpeg\Exception\InvalidArgumentException'); $this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$audio->addFilter($filter); $audio->addFilter($filter);
} }
@ -70,19 +71,19 @@ class AudioTest extends AbstractStreamableTestCase
->method('getExtraParams') ->method('getExtraParams')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface'); $configuration = $this->getMockBuilder('Alchemy\BinaryDriver\ConfigurationInterface')->getMock();
$driver->expects($this->any()) $driver->expects($this->any())
->method('getConfiguration') ->method('getConfiguration')
->will($this->returnValue($configuration)); ->will($this->returnValue($configuration));
$failure = new ExecutionFailureException('failed to encode'); $failure = new RuntimeException('failed to encode');
$driver->expects($this->once()) $driver->expects($this->once())
->method('command') ->method('command')
->will($this->throwException($failure)); ->will($this->throwException($failure));
$audio = new Audio(__FILE__, $driver, $ffprobe); $audio = new Audio(__FILE__, $driver, $ffprobe);
$this->setExpectedException('FFMpeg\Exception\RuntimeException'); $this->expectException('\FFMpeg\Exception\RuntimeException');
$audio->save($format, $outputPathfile); $audio->save($format, $outputPathfile);
} }

View file

@ -2,6 +2,7 @@
namespace Tests\FFMpeg\Unit\Media; namespace Tests\FFMpeg\Unit\Media;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Video; use FFMpeg\Media\Video;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Format\VideoInterface; use FFMpeg\Format\VideoInterface;
@ -93,13 +94,13 @@ class VideoTest extends AbstractStreamableTestCase
->method('getConfiguration') ->method('getConfiguration')
->will($this->returnValue($configuration)); ->will($this->returnValue($configuration));
$failure = new ExecutionFailureException('failed to encode'); $failure = new RuntimeException('failed to encode');
$driver->expects($this->once()) $driver->expects($this->once())
->method('command') ->method('command')
->will($this->throwException($failure)); ->will($this->throwException($failure));
$video = new Video(__FILE__, $driver, $ffprobe); $video = new Video(__FILE__, $driver, $ffprobe);
$this->setExpectedException('FFMpeg\Exception\RuntimeException'); $this->expectException('\FFMpeg\Exception\RuntimeException');
$video->save($format, $outputPathfile); $video->save($format, $outputPathfile);
} }