Skip to content

Commit

Permalink
fix mustRun() in sigchild environments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xabbuh committed Aug 28, 2014
1 parent cf02d55 commit b764f6c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Expand Up @@ -427,7 +427,7 @@ public function testSuccessfulMustRunHasCorrectExitCode()
}

/**
* @expectedException Symfony\Component\Process\Exception\ProcessFailedException
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
*/
public function testMustRunThrowsException()
{
Expand Down Expand Up @@ -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.'),
);
}

Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit b764f6c

Please sign in to comment.