Add timeout getter and setter
This commit is contained in:
parent
0567c42f07
commit
94c13056e4
2 changed files with 63 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
namespace FFMpeg;
|
namespace FFMpeg;
|
||||||
|
|
||||||
use FFMpeg\Exception\BinaryNotFoundException;
|
use FFMpeg\Exception\BinaryNotFoundException;
|
||||||
|
use FFMpeg\Exception\InvalidArgumentException;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Symfony\Component\Process\ExecutableFinder;
|
use Symfony\Component\Process\ExecutableFinder;
|
||||||
|
|
||||||
|
|
@ -50,7 +51,35 @@ abstract class Binary implements AdapterInterface
|
||||||
|
|
||||||
$this->binary = $binary;
|
$this->binary = $binary;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->setTimeout($timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current timeout for underlying processes.
|
||||||
|
*
|
||||||
|
* @return integer|float
|
||||||
|
*/
|
||||||
|
public function getTimeout()
|
||||||
|
{
|
||||||
|
return $this->timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the timeout for the underlying processes, use 0 to disable timeout.
|
||||||
|
*
|
||||||
|
* @param integer|float $timeout
|
||||||
|
*
|
||||||
|
* @return Binary
|
||||||
|
*/
|
||||||
|
public function setTimeout($timeout)
|
||||||
|
{
|
||||||
|
if (0 > $timeout) {
|
||||||
|
throw new InvalidArgumentException('Timeout must be a positive value');
|
||||||
|
}
|
||||||
|
|
||||||
$this->timeout = $timeout;
|
$this->timeout = $timeout;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,40 @@ class BinaryTest extends \PHPUnit_Framework_TestCase
|
||||||
$binary = new BinaryTester('pretty_binary', $this->logger);
|
$binary = new BinaryTester('pretty_binary', $this->logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTimeout()
|
||||||
|
{
|
||||||
|
$tester = BinaryTester::load($this->logger, 200);
|
||||||
|
$this->assertEquals(200, $tester->getTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDefaultTimeout()
|
||||||
|
{
|
||||||
|
$tester = BinaryTester::load($this->logger);
|
||||||
|
$this->assertEquals(60, $tester->getTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoTimeout()
|
||||||
|
{
|
||||||
|
$tester = BinaryTester::load($this->logger, 0);
|
||||||
|
$this->assertEquals(0, $tester->getTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetTimeout()
|
||||||
|
{
|
||||||
|
$tester = BinaryTester::load($this->logger);
|
||||||
|
$tester->setTimeout(200);
|
||||||
|
$this->assertEquals(200, $tester->getTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \FFMpeg\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testSetInvalidTimeout()
|
||||||
|
{
|
||||||
|
$tester = BinaryTester::load($this->logger);
|
||||||
|
$tester->setTimeout(-1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FFMpeg\Binary::load
|
* @covers FFMpeg\Binary::load
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue