fix mustRun() in sigchild environments
When being run in sigchild environments, the sigchild compatibility mode needs to be enabled to be able to call `getExitCode()`. Since `mustRun()` uses `getExitCode()` to determine whether or not a process terminated successfully, it cannot be used in sigchild environments when the sigchild compatibility mode is disabled.
This commit is contained in:
parent
cf02d5582b
commit
b764f6c61e
@ -215,9 +215,16 @@ class Process
|
||||
* @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);
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Process\Exception\ProcessFailedException
|
||||
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
|
||||
*/
|
||||
public function testMustRunThrowsException()
|
||||
{
|
||||
@ -990,20 +990,20 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @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.'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,15 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
|
||||
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 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
|
||||
$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}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user