Add Binary tests
This commit is contained in:
parent
aaa029382a
commit
3890100388
3 changed files with 93 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ abstract class Binary implements AdapterInterface
|
|||
{
|
||||
if ('' === $binary = self::autodetect(static::getBinaryName()))
|
||||
{
|
||||
throw new \Exception('Binary not found');
|
||||
throw new Exception\BinaryNotFoundException('Binary not found');
|
||||
}
|
||||
|
||||
return new static($binary, $logger);
|
||||
|
|
@ -43,7 +43,7 @@ abstract class Binary implements AdapterInterface
|
|||
|
||||
if ( ! $process->isSuccessful() && ! $bypass_errors)
|
||||
{
|
||||
throw new Exception\RuntimeException('Failed to execute ' . $command);
|
||||
throw new \RuntimeException('Failed to execute ' . $command);
|
||||
}
|
||||
|
||||
$result = $process->getOutput();
|
||||
|
|
|
|||
8
src/FFMpeg/Exception/BinaryNotFoundException.php
Normal file
8
src/FFMpeg/Exception/BinaryNotFoundException.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Exception;
|
||||
|
||||
class BinaryNotFoundException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
83
tests/src/FFMpeg/BinaryTest.php
Normal file
83
tests/src/FFMpeg/BinaryTest.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg;
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../src/FFMpeg/Binary.php';
|
||||
|
||||
class BinaryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Binary
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* @covers FFMpeg\Binary::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$binary = new BinaryTester('pretty_binary');
|
||||
$binary = new BinaryTester('pretty_binary', new \Monolog\Logger('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FFMpeg\Binary::load
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
BinaryTester::load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FFMpeg\Binary::load
|
||||
* @expectedException \FFMpeg\Exception\BinaryNotFoundException
|
||||
*/
|
||||
public function testLoadWrongBinary()
|
||||
{
|
||||
BinaryTesterWrongBinary::load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FFMpeg\Binary::run
|
||||
*/
|
||||
public function testRun()
|
||||
{
|
||||
BinaryTester::runner('php --version');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FFMpeg\Binary::run
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testRunFail()
|
||||
{
|
||||
BinaryTester::runner('aphp -version');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BinaryTester extends Binary
|
||||
{
|
||||
|
||||
protected static function getBinaryName()
|
||||
{
|
||||
return 'php';
|
||||
}
|
||||
|
||||
public static function runner($command, $bypass_errors = false)
|
||||
{
|
||||
return self::run($command, $bypass_errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BinaryTesterWrongBinary extends Binary
|
||||
{
|
||||
|
||||
protected static function getBinaryName()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue