diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index e914a4fe0113..44523b7ac293 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -215,9 +215,16 @@ public function run($callback = null) * @param callable|null $callback * * @return self + * + * @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled + * @throws ProcessFailedException if the process didn't terminate successfully */ public function mustRun($callback = null) { + if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) { + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'); + } + if (0 !== $this->run($callback)) { throw new ProcessFailedException($this); } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index e1e173fd2c98..dbc92e264853 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -427,7 +427,7 @@ public function testSuccessfulMustRunHasCorrectExitCode() } /** - * @expectedException Symfony\Component\Process\Exception\ProcessFailedException + * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException */ public function testMustRunThrowsException() { @@ -990,20 +990,20 @@ public function testSetNullIdleTimeoutWhileOutputIsDisabled() /** * @dataProvider provideStartMethods */ - public function testStartWithACallbackAndDisabledOutput($startMethod) + public function testStartWithACallbackAndDisabledOutput($startMethod, $exception, $exceptionMessage) { $p = $this->getProcess('php -r "usleep(500000);"'); $p->disableOutput(); - $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'); + $this->setExpectedException($exception, $exceptionMessage); call_user_func(array($p, $startMethod), function () {}); } public function provideStartMethods() { return array( - array('start'), - array('run'), - array('mustRun'), + array('start', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'), + array('run', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'), + array('mustRun', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'), ); } diff --git a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index 6d10a7c6acf5..01dca1590b07 100644 --- a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php @@ -49,6 +49,15 @@ public function testExitCodeCommandFailed() parent::testExitCodeCommandFailed(); } + /** + * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. + */ + public function testMustRun() + { + parent::testMustRun(); + } + /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. @@ -232,6 +241,15 @@ public function testRunProcessWithTimeout() $this->markTestSkipped('Signal (required for timeout) is not supported in sigchild environment'); } + public function provideStartMethods() + { + return array( + array('start', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'), + array('run', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'), + array('mustRun', 'Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'), + ); + } + /** * {@inheritdoc} */