Add bc layer for older php and phpunit versions

This commit is contained in:
Alexander Schranz 2020-02-19 21:52:13 +01:00
commit 7474bf936f
16 changed files with 90 additions and 99 deletions

View file

@ -4,57 +4,49 @@ namespace Tests\FFMpeg;
use PHPUnit\Framework\TestCase;
class BaseTestCase extends TestCase
{
public function assertScalar($value, $message = '')
/**
* This is a BC Layer to support phpunit 4.8 needed for php <= 5.5.
*/
if (class_exists('PHPUnit_Runner_Version')
&& version_compare(\PHPUnit_Runner_Version::id(), '5', '<')) {
class BaseTestCase extends TestCase
{
$this->assertTrue(is_scalar($value), $message);
}
/**
* Can be removed when phpunit 4.8 (<= needed for php 5.5) support is removed.
*/
public function assertIsArray($value, $message = '')
{
$this->assertTrue(is_array($value), $message);
}
/**
* Can be removed when phpunit 4.8 (<= needed for php 5.5) support is removed.
*/
public function assertIsInt($value, $message = '')
{
$this->assertTrue(is_int($value), $message);
}
/**
* Can be removed when phpunit 4.8 (<= needed for php 5.5) support is removed.
*/
public function assertIsBool($value, $message = '')
{
$this->assertTrue(is_bool($value), $message);
}
/**
* Can be removed when phpunit 4.8 (<= needed for php 5.5) support is removed.
*/
public function assertIsString($value, $message = '')
{
$this->assertTrue(is_string($value), $message);
}
/**
* Can be removed when phpunit 4.8 (<= needed for php 5.5) support is removed.
*/
public function expectException($exception)
{
// PHPUnt BC Layer
if (method_exists(get_parent_class(), 'expectException')) {
parent::expectException($exception);
return;
public static function assertScalar($value, $message = '')
{
self::assertTrue(is_scalar($value), $message);
}
$this->setExpectedException($exception);
public static function assertIsArray($value, $message = '')
{
self::assertTrue(is_array($value), $message);
}
public static function assertIsInt($value, $message = '')
{
self::assertTrue(is_int($value), $message);
}
public static function assertIsBool($value, $message = '')
{
self::assertTrue(is_bool($value), $message);
}
public static function assertIsString($value, $message = '')
{
self::assertTrue(is_string($value), $message);
}
public function expectException($exception, $message = null)
{
$this->setExpectedException($exception, $message);
}
}
} else {
class BaseTestCase extends TestCase
{
public function assertScalar($value, $message = '')
{
$this->assertTrue(is_scalar($value), $message);
}
}
}

View file

@ -28,8 +28,6 @@ class TimeCodeTest extends TestCase
);
}
/**
*/
public function testFromInvalidString()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');

View file

@ -41,8 +41,6 @@ class FFMpegDriverTest extends TestCase
$this->assertEquals($conf, $ffmpeg->getConfiguration());
}
/**
*/
public function testCreateFailureThrowsAnException()
{
$this->expectException('\FFMpeg\Exception\ExecutableNotFoundException');

View file

@ -41,8 +41,6 @@ class FFProbeDriverTest extends TestCase
$this->assertEquals($conf, $ffprobe->getConfiguration());
}
/**
*/
public function testCreateFailureThrowsAnException()
{
$this->expectException('\FFMpeg\Exception\ExecutableNotFoundException');

View file

@ -8,12 +8,12 @@ use FFMpeg\FFProbe\DataMapping\Stream;
class FFMpegTest extends TestCase
{
/**
* @expectedExceptionMessage Unable to probe "/path/to/unknown/file".
*/
public function testOpenInvalid()
{
$this->expectException('\FFMpeg\Exception\RuntimeException');
$this->expectException(
'\FFMpeg\Exception\RuntimeException',
'Unable to probe "/path/to/unknown/file"'
);
$ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $this->getFFProbeMock());
$ffmpeg->open('/path/to/unknown/file');
}
@ -57,8 +57,6 @@ class FFMpegTest extends TestCase
$this->assertInstanceOf('FFMpeg\Media\Video', $ffmpeg->open(__FILE__));
}
/**
*/
public function testOpenUnknown()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');

View file

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

View file

@ -20,8 +20,6 @@ class MapperTest extends TestCase
$this->assertEquals($expected, $mapper->map($type, $data));
}
/**
*/
public function testMapInvalidArgument()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');

View file

@ -2,26 +2,28 @@
namespace Tests\FFMpeg\Unit\FFProbe;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use FFMpeg\Exception\RuntimeException;
use Tests\FFMpeg\Unit\TestCase;
use FFMpeg\FFProbe\OptionsTester;
class OptionsTesterTest extends TestCase
{
/**
* @expectedExceptionMessage Your FFProbe version is too old and does not support `-help` option, please upgrade.
*/
public function testHasOptionWithOldFFProbe()
{
$this->expectException('\FFMpeg\Exception\RuntimeException');
$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(array('-help', '-loglevel', 'quiet'))
->will($this->throwException(new RuntimeException('Failed to execute')));
->will($this->throwException($executionFailerExceptionMock));
$tester = new OptionsTester($ffprobe, $cache);
$tester->has('-print_format');

View file

@ -17,8 +17,6 @@ class OutputParserTest extends TestCase
$this->assertEquals($expectedOutput, $parser->parse($type, $data));
}
/**
*/
public function testParseWithInvalidArgument()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');

View file

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

View file

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

View file

@ -34,8 +34,6 @@ abstract class AudioTestCase extends TestCase
}
}
/**
*/
public function testSetInvalidAudioCodec()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
@ -59,16 +57,12 @@ abstract class AudioTestCase extends TestCase
$this->assertEquals(256, $format->getAudioKiloBitrate());
}
/**
*/
public function testSetInvalidKiloBitrate()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioKiloBitrate(0);
}
/**
*/
public function testSetNegativeKiloBitrate()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
@ -87,16 +81,12 @@ abstract class AudioTestCase extends TestCase
$this->assertEquals(2, $format->getAudioChannels());
}
/**
*/
public function testSetInvalidChannels()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');
$this->getFormat()->setAudioChannels(0);
}
/**
*/
public function testSetNegativeChannels()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');

View file

@ -39,8 +39,6 @@ abstract class VideoTestCase extends AudioTestCase
$this->assertEquals(2560, $format->getKiloBitrate());
}
/**
*/
public function testSetInvalidVideoCodec()
{
$this->expectException('\FFMpeg\Exception\InvalidArgumentException');