diff --git a/src/FFMpeg/Binary.php b/src/FFMpeg/Binary.php index 9975a11..36fe496 100644 --- a/src/FFMpeg/Binary.php +++ b/src/FFMpeg/Binary.php @@ -12,6 +12,7 @@ namespace FFMpeg; use FFMpeg\Exception\BinaryNotFoundException; +use FFMpeg\Exception\InvalidArgumentException; use Monolog\Logger; use Symfony\Component\Process\ExecutableFinder; @@ -50,7 +51,35 @@ abstract class Binary implements AdapterInterface $this->binary = $binary; $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; + + return $this; } /** diff --git a/tests/src/FFMpeg/BinaryTest.php b/tests/src/FFMpeg/BinaryTest.php index 081d482..5863da0 100644 --- a/tests/src/FFMpeg/BinaryTest.php +++ b/tests/src/FFMpeg/BinaryTest.php @@ -29,6 +29,40 @@ class BinaryTest extends \PHPUnit_Framework_TestCase $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 */