bug #16915 [Process] Enhance compatiblity with --enable-sigchild (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Enhance compatiblity with --enable-sigchild

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16888
| License       | MIT
| Doc PR        | -

This is complete rewrite of the fallback `--enable-sigchild` handling in the Process class.
It removes most of the differences between this and a non-sigchild-enabled php.
Which means the test suite doesn't need anymore to be replayed 3 times (which is how I started this PR, looking for a way to test this component in less time).

I validated this with a locally compiled php, sigchild-enabled. Green.
Changes affect only this special-mode php.

Ping @romainneutron and @Seldaek (original writer of the sigchild support)

Submitted on 2.3 as bugfix, which it is to me.

Commits
-------

e7cc4aa [Process] Enhance compatiblity with --enable-sigchild
This commit is contained in:
Nicolas Grekas 2015-12-10 17:39:45 +01:00
commit 423f83f75e
8 changed files with 184 additions and 706 deletions

View File

@ -10,6 +10,7 @@ addons:
cache: cache:
directories: directories:
- .phpunit - .phpunit
- php-5.3.9
matrix: matrix:
include: include:
@ -32,6 +33,7 @@ env:
before_install: before_install:
- if [[ "$deps" = "no" ]] && [[ "$TRAVIS_PHP_VERSION" =~ 5.[45] ]] && [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then export deps=skip; fi; - if [[ "$deps" = "no" ]] && [[ "$TRAVIS_PHP_VERSION" =~ 5.[45] ]] && [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then export deps=skip; fi;
- if [[ $deps = no && $TRAVIS_PHP_VERSION = 5.3 && ! -d php-5.3.9/sapi ]]; then wget http://museum.php.net/php5/php-5.3.9.tar.bz2; tar -xjf php-5.3.9.tar.bz2; (cd php-5.3.9; ./configure --enable-sigchild --enable-pcntl; make -j2); fi;
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi; - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi;
- echo "memory_limit = -1" >> $INI_FILE - echo "memory_limit = -1" >> $INI_FILE
- echo "session.gc_probability = 0" >> $INI_FILE - echo "session.gc_probability = 0" >> $INI_FILE
@ -54,6 +56,7 @@ install:
script: script:
- if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu '$PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi; - if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu '$PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi;
- if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi; - if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi;
- if [[ $deps = no && $TRAVIS_PHP_VERSION = 5.3 ]]; then echo -e "1\\n0" | parallel --gnu 'echo -e "\\nPHP --enable-sigchild enhanced={}" && ENHANCE_SIGCHLD={} php-5.3.9/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi;
- if [ "$deps" = "high" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi; - if [ "$deps" = "high" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
- if [ "$deps" = "low" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi; - if [ "$deps" = "low" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
- if [ "$deps" = "skip" ]; then echo 'This matrix line is skipped for pull requests.'; fi; - if [ "$deps" = "skip" ]; then echo 'This matrix line is skipped for pull requests.'; fi;

View File

@ -46,7 +46,7 @@ class Process
private $timeout; private $timeout;
private $options; private $options;
private $exitcode; private $exitcode;
private $fallbackExitcode; private $fallbackStatus = array();
private $processInformation; private $processInformation;
private $stdout; private $stdout;
private $stderr; private $stderr;
@ -65,6 +65,14 @@ class Process
private $latestSignal; private $latestSignal;
private static $sigchild; private static $sigchild;
private static $posixSignals = array(
1 => 1, // SIGHUP
2 => 2, // SIGINT
3 => 3, // SIGQUIT
6 => 6, // SIGABRT
14 => 14, // SIGALRM
15 => 15, // SIGTERM
);
/** /**
* Exit codes translation table. * Exit codes translation table.
@ -339,17 +347,9 @@ class Process
* Returns the Pid (process identifier), if applicable. * Returns the Pid (process identifier), if applicable.
* *
* @return int|null The process id if running, null otherwise * @return int|null The process id if running, null otherwise
*
* @throws RuntimeException In case --enable-sigchild is activated
*/ */
public function getPid() public function getPid()
{ {
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.');
}
$this->updateStatus(false);
return $this->isRunning() ? $this->processInformation['pid'] : null; return $this->isRunning() ? $this->processInformation['pid'] : null;
} }
@ -361,7 +361,7 @@ class Process
* @return Process * @return Process
* *
* @throws LogicException In case the process is not running * @throws LogicException In case the process is not running
* @throws RuntimeException In case --enable-sigchild is activated * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
* @throws RuntimeException In case of failure * @throws RuntimeException In case of failure
*/ */
public function signal($signal) public function signal($signal)
@ -467,7 +467,9 @@ class Process
*/ */
public function getExitCode() public function getExitCode()
{ {
if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) { if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'); throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
} }
@ -484,8 +486,6 @@ class Process
* *
* @return null|string A string representation for the exit status code, null if the Process is not terminated. * @return null|string A string representation for the exit status code, null if the Process is not terminated.
* *
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
*
* @see http://tldp.org/LDP/abs/html/exitcodes.html * @see http://tldp.org/LDP/abs/html/exitcodes.html
* @see http://en.wikipedia.org/wiki/Unix_signal * @see http://en.wikipedia.org/wiki/Unix_signal
*/ */
@ -522,12 +522,12 @@ class Process
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireProcessIsTerminated(__FUNCTION__);
if ($this->isSigchildEnabled()) { if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
} }
$this->updateStatus(false);
return $this->processInformation['signaled']; return $this->processInformation['signaled'];
} }
@ -545,12 +545,12 @@ class Process
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireProcessIsTerminated(__FUNCTION__);
if ($this->isSigchildEnabled()) { if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
} }
$this->updateStatus(false);
return $this->processInformation['termsig']; return $this->processInformation['termsig'];
} }
@ -567,8 +567,6 @@ class Process
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireProcessIsTerminated(__FUNCTION__);
$this->updateStatus(false);
return $this->processInformation['stopped']; return $this->processInformation['stopped'];
} }
@ -585,8 +583,6 @@ class Process
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireProcessIsTerminated(__FUNCTION__);
$this->updateStatus(false);
return $this->processInformation['stopsig']; return $this->processInformation['stopsig'];
} }
@ -660,7 +656,7 @@ class Process
usleep(1000); usleep(1000);
} while ($this->isRunning() && microtime(true) < $timeoutMicro); } while ($this->isRunning() && microtime(true) < $timeoutMicro);
if ($this->isRunning() && !$this->isSigchildEnabled()) { if ($this->isRunning()) {
// Avoid exception here: process is supposed to be running, but it might have stopped just // Avoid exception here: process is supposed to be running, but it might have stopped just
// after this line. In any case, let's silently discard the error, we cannot do anything. // after this line. In any case, let's silently discard the error, we cannot do anything.
$this->doSignal($signal ?: 9, false); $this->doSignal($signal ?: 9, false);
@ -998,9 +994,15 @@ class Process
if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors = array_merge($descriptors, array(array('pipe', 'w'))); $descriptors[3] = array('pipe', 'w');
$this->commandline = '('.$this->commandline.') 3>/dev/null; code=$?; echo $code >&3; exit $code'; $trap = '';
foreach (self::$posixSignals as $s) {
$trap .= "trap 'echo s$s >&3' $s;";
}
$this->commandline = $trap.'{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$this->commandline .= 'pid=$!; echo p$pid >&3; wait $pid; code=$?; echo x$code >&3; exit $code';
} }
return $descriptors; return $descriptors;
@ -1047,10 +1049,13 @@ class Process
} }
$this->processInformation = proc_get_status($this->process); $this->processInformation = proc_get_status($this->process);
$this->captureExitCode();
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true); $this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->processInformation = $this->fallbackStatus + $this->processInformation;
}
if (!$this->processInformation['running']) { if (!$this->processInformation['running']) {
$this->close(); $this->close();
} }
@ -1067,7 +1072,7 @@ class Process
return self::$sigchild; return self::$sigchild;
} }
if (!function_exists('phpinfo')) { if (!function_exists('phpinfo') || defined('HHVM_VERSION')) {
return self::$sigchild = false; return self::$sigchild = false;
} }
@ -1093,24 +1098,24 @@ class Process
$callback = $this->callback; $callback = $this->callback;
foreach ($result as $type => $data) { foreach ($result as $type => $data) {
if (3 == $type) { if (3 === $type) {
$this->fallbackExitcode = (int) $data; foreach (explode("\n", substr($data, 0, -1)) as $data) {
if ('p' === $data[0]) {
$this->fallbackStatus['pid'] = (int) substr($data, 1);
} elseif ('s' === $data[0]) {
$this->fallbackStatus['signaled'] = true;
$this->fallbackStatus['exitcode'] = -1;
$this->fallbackStatus['termsig'] = (int) substr($data, 1);
} elseif ('x' === $data[0] && !isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) substr($data, 1);
}
}
} else { } else {
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data); $callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
} }
} }
} }
/**
* Captures the exitcode if mentioned in the process information.
*/
private function captureExitCode()
{
if (isset($this->processInformation['exitcode']) && -1 != $this->processInformation['exitcode']) {
$this->exitcode = $this->processInformation['exitcode'];
}
}
/** /**
* Closes process resource, closes file handles, sets the exitcode. * Closes process resource, closes file handles, sets the exitcode.
* *
@ -1120,19 +1125,19 @@ class Process
{ {
$this->processPipes->close(); $this->processPipes->close();
if (is_resource($this->process)) { if (is_resource($this->process)) {
$exitcode = proc_close($this->process); proc_close($this->process);
} else {
$exitcode = -1;
} }
$this->exitcode = $this->processInformation['exitcode'];
$this->exitcode = -1 !== $exitcode ? $exitcode : (null !== $this->exitcode ? $this->exitcode : -1);
$this->status = self::STATUS_TERMINATED; $this->status = self::STATUS_TERMINATED;
if (-1 === $this->exitcode && null !== $this->fallbackExitcode) { if (-1 === $this->exitcode) {
$this->exitcode = $this->fallbackExitcode; if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
} elseif (-1 === $this->exitcode && $this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
// if process has been signaled, no exitcode but a valid termsig, apply Unix convention // if process has been signaled, no exitcode but a valid termsig, apply Unix convention
$this->exitcode = 128 + $this->processInformation['termsig']; $this->exitcode = 128 + $this->processInformation['termsig'];
} elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->processInformation['signaled'] = true;
$this->processInformation['termsig'] = -1;
}
} }
// Free memory from self-reference callback created by buildCallback // Free memory from self-reference callback created by buildCallback
@ -1151,7 +1156,7 @@ class Process
$this->starttime = null; $this->starttime = null;
$this->callback = null; $this->callback = null;
$this->exitcode = null; $this->exitcode = null;
$this->fallbackExitcode = null; $this->fallbackStatus = array();
$this->processInformation = null; $this->processInformation = null;
$this->stdout = null; $this->stdout = null;
$this->stderr = null; $this->stderr = null;
@ -1171,7 +1176,7 @@ class Process
* @return bool True if the signal was sent successfully, false otherwise * @return bool True if the signal was sent successfully, false otherwise
* *
* @throws LogicException In case the process is not running * @throws LogicException In case the process is not running
* @throws RuntimeException In case --enable-sigchild is activated * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
* @throws RuntimeException In case of failure * @throws RuntimeException In case of failure
*/ */
private function doSignal($signal, $throwException) private function doSignal($signal, $throwException)
@ -1184,9 +1189,9 @@ class Process
return false; return false;
} }
if ($this->isSigchildEnabled()) { if ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled() && !isset(self::$posixSignals[$signal]) && !(function_exists('posix_kill') && @posix_kill($this->getPid(), $signal))) {
if ($throwException) { if ($throwException) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); throw new RuntimeException('This PHP has been compiled with --enable-sigchild and posix_kill() is not available.');
} }
return false; return false;
@ -1211,7 +1216,10 @@ class Process
return false; return false;
} }
$this->latestSignal = $signal; $this->latestSignal = (int) $signal;
$this->fallbackStatus['signaled'] = true;
$this->fallbackStatus['exitcode'] = -1;
$this->fallbackStatus['termsig'] = $this->latestSignal;
return true; return true;
} }

View File

@ -30,24 +30,20 @@ PHP
public function testCommandLine() public function testCommandLine()
{ {
if ('phpdbg' === PHP_SAPI) {
$this->markTestSkipped('phpdbg SAPI is not supported by this test.');
}
$process = new PhpProcess(<<<PHP $process = new PhpProcess(<<<PHP
<?php echo 'foobar'; <?php echo 'foobar';
PHP PHP
); );
$f = new PhpExecutableFinder(); $commandLine = $process->getCommandLine();
$commandLine = $f->find();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start'); $f = new PhpExecutableFinder();
$this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start');
$process->start(); $process->start();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start'); $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
$process->wait(); $process->wait();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait'); $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
} }
} }

View File

@ -1,22 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
use Symfony\Component\Process\Process;
class ProcessInSigchildEnvironment extends Process
{
protected function isSigchildEnabled()
{
return true;
}
}

View File

@ -20,9 +20,10 @@ use Symfony\Component\Process\ProcessPipes;
/** /**
* @author Robert Schönthal <seroscho@googlemail.com> * @author Robert Schönthal <seroscho@googlemail.com>
*/ */
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase class ProcessTest extends \PHPUnit_Framework_TestCase
{ {
protected static $phpBin; private static $phpBin;
private static $notEnhancedSigchild = false;
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
@ -71,12 +72,11 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$this->assertNull($p->getTimeout()); $this->assertNull($p->getTimeout());
} }
/**
* @requires extension pcntl
*/
public function testStopWithTimeoutIsActuallyWorking() public function testStopWithTimeoutIsActuallyWorking()
{ {
if (!extension_loaded('pcntl')) {
$this->markTestSkipped('Extension pcntl is required.');
}
// exec is mandatory here since we send a signal to the process // exec is mandatory here since we send a signal to the process
// see https://github.com/symfony/symfony/issues/5030 about prepending // see https://github.com/symfony/symfony/issues/5030 about prepending
// command with exec // command with exec
@ -124,7 +124,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{ {
$data = ''; $data = '';
$process = $this->getProcess('echo foo && php -r "sleep(1);" && echo foo'); $process = $this->getProcess('echo foo && '.self::$phpBin.' -r "sleep(1);" && echo foo');
$process->start(function ($type, $buffer) use (&$data) { $process->start(function ($type, $buffer) use (&$data) {
$data .= $buffer; $data .= $buffer;
}); });
@ -401,6 +401,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX exit code'); $this->markTestSkipped('Windows does not support POSIX exit code');
} }
$this->skipIfNotEnhancedSigchild();
// such command run in bash return an exitcode 127 // such command run in bash return an exitcode 127
$process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis'); $process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
@ -429,6 +430,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does have /dev/tty support'); $this->markTestSkipped('Windows does have /dev/tty support');
} }
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo "foo" >> /dev/null'); $process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTty(true); $process->setTty(true);
@ -437,6 +439,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($process->isSuccessful()); $this->assertTrue($process->isSuccessful());
} }
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage TTY mode is not supported on Windows platform.
*/
public function testTTYInWindowsEnvironment() public function testTTYInWindowsEnvironment()
{ {
if ('\\' !== DIRECTORY_SEPARATOR) { if ('\\' !== DIRECTORY_SEPARATOR) {
@ -445,18 +451,21 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$process = $this->getProcess('echo "foo" >> /dev/null'); $process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTty(false); $process->setTty(false);
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'TTY mode is not supported on Windows platform.');
$process->setTty(true); $process->setTty(true);
} }
public function testExitCodeTextIsNullWhenExitCodeIsNull() public function testExitCodeTextIsNullWhenExitCodeIsNull()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(''); $process = $this->getProcess('');
$this->assertNull($process->getExitCodeText()); $this->assertNull($process->getExitCodeText());
} }
public function testExitCodeText() public function testExitCodeText()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(''); $process = $this->getProcess('');
$r = new \ReflectionObject($process); $r = new \ReflectionObject($process);
$p = $r->getProperty('exitcode'); $p = $r->getProperty('exitcode');
@ -485,6 +494,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testGetExitCodeIsNullOnStart() public function testGetExitCodeIsNullOnStart()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"'); $process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
$this->assertNull($process->getExitCode()); $this->assertNull($process->getExitCode());
$process->start(); $process->start();
@ -495,6 +506,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testGetExitCodeIsNullOnWhenStartingAgain() public function testGetExitCodeIsNullOnWhenStartingAgain()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"'); $process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
$process->run(); $process->run();
$this->assertEquals(0, $process->getExitCode()); $this->assertEquals(0, $process->getExitCode());
@ -506,6 +519,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testGetExitCode() public function testGetExitCode()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->run(); $process->run();
$this->assertSame(0, $process->getExitCode()); $this->assertSame(0, $process->getExitCode());
@ -541,6 +556,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testIsSuccessful() public function testIsSuccessful()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->run(); $process->run();
$this->assertTrue($process->isSuccessful()); $this->assertTrue($process->isSuccessful());
@ -548,6 +565,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testIsSuccessfulOnlyAfterTerminated() public function testIsSuccessfulOnlyAfterTerminated()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"'); $process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
$process->start(); $process->start();
@ -562,6 +581,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testIsNotSuccessful() public function testIsNotSuccessful()
{ {
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);throw new \Exception(\'BOUM\');"'); $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);throw new \Exception(\'BOUM\');"');
$process->start(); $process->start();
$this->assertTrue($process->isRunning()); $this->assertTrue($process->isRunning());
@ -574,6 +595,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals'); $this->markTestSkipped('Windows does not support POSIX signals');
} }
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->run(); $process->run();
@ -585,6 +607,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals'); $this->markTestSkipped('Windows does not support POSIX signals');
} }
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->run(); $process->run();
@ -596,6 +619,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals'); $this->markTestSkipped('Windows does not support POSIX signals');
} }
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->run(); $process->run();
@ -607,6 +631,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals'); $this->markTestSkipped('Windows does not support POSIX signals');
} }
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"'); $process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
$process->start(); $process->start();
@ -619,22 +644,25 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals'); $this->markTestSkipped('Windows does not support POSIX signals');
} }
$this->skipIfNotEnhancedSigchild();
// SIGTERM is only defined if pcntl extension is present
$termSignal = defined('SIGTERM') ? SIGTERM : 15;
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"'); $process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
$process->start(); $process->start();
$process->stop(); $process->stop();
$this->assertEquals($termSignal, $process->getTermSignal()); $this->assertEquals(15, $process->getTermSignal()); // SIGTERM
} }
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage The process has been signaled
*/
public function testProcessThrowsExceptionWhenExternallySignaled() public function testProcessThrowsExceptionWhenExternallySignaled()
{ {
if (!function_exists('posix_kill')) { if (!function_exists('posix_kill')) {
$this->markTestSkipped('Function posix_kill is required.'); $this->markTestSkipped('Function posix_kill is required.');
} }
$this->skipIfNotEnhancedSigchild(false);
$termSignal = defined('SIGKILL') ? SIGKILL : 9; $termSignal = defined('SIGKILL') ? SIGKILL : 9;
@ -642,7 +670,6 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$process->start(); $process->start();
posix_kill($process->getPid(), $termSignal); posix_kill($process->getPid(), $termSignal);
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'The process has been signaled with signal "9".');
$process->wait(); $process->wait();
} }
@ -725,7 +752,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
} }
$duration = microtime(true) - $start; $duration = microtime(true) - $start;
$this->assertLessThan(1, $duration); $this->assertLessThan(3, $duration);
throw $e; throw $e;
} }
@ -771,12 +798,11 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$this->assertNull($process->getPid()); $this->assertNull($process->getPid());
} }
/**
* @requires extension pcntl
*/
public function testSignal() public function testSignal()
{ {
if (!extension_loaded('pcntl')) {
$this->markTestSkipped('Extension pcntl is required.');
}
$process = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/SignalListener.php'); $process = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/SignalListener.php');
$process->start(); $process->start();
@ -789,11 +815,12 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Caught SIGUSR1', $process->getOutput()); $this->assertEquals('Caught SIGUSR1', $process->getOutput());
} }
/**
* @requires extension pcntl
*/
public function testExitCodeIsAvailableAfterSignal() public function testExitCodeIsAvailableAfterSignal()
{ {
if (!extension_loaded('pcntl')) { $this->skipIfNotEnhancedSigchild();
$this->markTestSkipped('Extension pcntl is required.');
}
$process = $this->getProcess('sleep 4'); $process = $this->getProcess('sleep 4');
$process->start(); $process->start();
@ -811,15 +838,12 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
/** /**
* @expectedException \Symfony\Component\Process\Exception\LogicException * @expectedException \Symfony\Component\Process\Exception\LogicException
* @expectedExceptionMessage Can not send signal on a non running process.
*/ */
public function testSignalProcessNotRunning() public function testSignalProcessNotRunning()
{ {
if (!extension_loaded('pcntl')) {
$this->markTestSkipped('Extension pcntl is required.');
}
$process = $this->getProcess(self::$phpBin.' -v'); $process = $this->getProcess(self::$phpBin.' -v');
$process->signal(SIGHUP); $process->signal(1); // SIGHUP
} }
/** /**
@ -901,6 +925,37 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$process->signal('Céphalopodes'); $process->signal('Céphalopodes');
} }
public function testStopTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
$process->stop();
});
$this->assertTrue(true, 'A call to stop() is not expected to cause wait() to throw a RuntimeException');
}
public function testKillSignalTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(9); // SIGKILL
}
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
public function testTermSignalTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(15); // SIGTERM
}
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
public function responsesCodeProvider() public function responsesCodeProvider()
{ {
return array( return array(
@ -962,7 +1017,38 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
* *
* @return Process * @return Process
*/ */
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array()); private function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
$process = new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
if (false !== $enhance = getenv('ENHANCE_SIGCHLD')) {
try {
$process->setEnhanceSigchildCompatibility(false);
$process->getExitCode();
$this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
} catch (RuntimeException $e) {
$this->assertSame('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.', $e->getMessage());
if ($enhance) {
$process->setEnhanceSigChildCompatibility(true);
} else {
self::$notEnhancedSigchild = true;
}
}
}
return $process;
}
private function skipIfNotEnhancedSigchild($expectException = true)
{
if (self::$notEnhancedSigchild) {
if ($expectException) {
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
} else {
$this->markTestSkipped('PHP is compiled with --enable-sigchild and enhanced mode is disabled.');
}
}
}
} }
class Stringifiable class Stringifiable

View File

@ -1,225 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
class SigchildDisabledProcessTest extends AbstractProcessTest
{
/**
* @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 testGetExitCode()
{
parent::testGetExitCode();
}
/**
* @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 testGetExitCodeIsNullOnStart()
{
parent::testGetExitCodeIsNullOnStart();
}
/**
* @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 testGetExitCodeIsNullOnWhenStartingAgain()
{
parent::testGetExitCodeIsNullOnWhenStartingAgain();
}
/**
* @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 testExitCodeCommandFailed()
{
parent::testExitCodeCommandFailed();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsSignaledIfStopped()
{
parent::testProcessIsSignaledIfStopped();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithTermSignal()
{
parent::testProcessWithTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsNotSignaled()
{
parent::testProcessIsNotSignaled();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignal()
{
parent::testProcessWithoutTermSignal();
}
public function testCheckTimeoutOnStartedProcess()
{
$this->markTestSkipped('Stopping with signal is not supported in sigchild environment');
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPid()
{
parent::testGetPid();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullBeforeStart()
{
parent::testGetPidIsNullBeforeStart();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullAfterRun()
{
parent::testGetPidIsNullAfterRun();
}
/**
* @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 testExitCodeText()
{
$process = $this->getProcess('qdfsmfkqsdfmqmsd');
$process->run();
$process->getExitCodeText();
}
/**
* @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 testExitCodeTextIsNullWhenExitCodeIsNull()
{
parent::testExitCodeTextIsNullWhenExitCodeIsNull();
}
/**
* @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 testIsSuccessful()
{
parent::testIsSuccessful();
}
/**
* @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 testIsSuccessfulOnlyAfterTerminated()
{
parent::testIsSuccessfulOnlyAfterTerminated();
}
/**
* @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 testIsNotSuccessful()
{
parent::testIsNotSuccessful();
}
/**
* @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 testTTYCommandExitCode()
{
parent::testTTYCommandExitCode();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled.
*/
public function testSignal()
{
parent::testSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignalIsNotSignaled()
{
parent::testProcessWithoutTermSignalIsNotSignaled();
}
public function testStopWithTimeoutIsActuallyWorking()
{
$this->markTestSkipped('Stopping with signal is not supported in sigchild environment');
}
public function testProcessThrowsExceptionWhenExternallySignaled()
{
$this->markTestSkipped('Retrieving Pid is not supported in sigchild environment');
}
public function testExitCodeIsAvailableAfterSignal()
{
$this->markTestSkipped('Signal is not supported in sigchild environment');
}
public function testRunProcessWithTimeout()
{
$this->markTestSkipped('Signal (required for timeout) is not supported in sigchild environment');
}
/**
* {@inheritdoc}
*/
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
$process->setEnhanceSigchildCompatibility(false);
return $process;
}
}

View File

@ -1,152 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
class SigchildEnabledProcessTest extends AbstractProcessTest
{
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsSignaledIfStopped()
{
parent::testProcessIsSignaledIfStopped();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithTermSignal()
{
parent::testProcessWithTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsNotSignaled()
{
parent::testProcessIsNotSignaled();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignal()
{
parent::testProcessWithoutTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPid()
{
parent::testGetPid();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullBeforeStart()
{
parent::testGetPidIsNullBeforeStart();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullAfterRun()
{
parent::testGetPidIsNullAfterRun();
}
public function testExitCodeText()
{
$process = $this->getProcess('qdfsmfkqsdfmqmsd');
$process->run();
$this->assertInternalType('string', $process->getExitCodeText());
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled.
*/
public function testSignal()
{
parent::testSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignalIsNotSignaled()
{
parent::testProcessWithoutTermSignalIsNotSignaled();
}
public function testProcessThrowsExceptionWhenExternallySignaled()
{
$this->markTestSkipped('Retrieving Pid is not supported in sigchild environment');
}
public function testExitCodeIsAvailableAfterSignal()
{
$this->markTestSkipped('Signal is not supported in sigchild environment');
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage The process timed-out.
*/
public function testStartAfterATimeout()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Restarting a timed-out process on Windows is not supported in sigchild environment');
}
parent::testStartAfterATimeout();
}
public function testStopWithTimeoutIsActuallyWorking()
{
$this->markTestSkipped('Stopping with signal is not supported in sigchild environment');
}
public function testRunProcessWithTimeout()
{
$this->markTestSkipped('Signal (required for timeout) is not supported in sigchild environment');
}
public function testCheckTimeoutOnStartedProcess()
{
$this->markTestSkipped('Signal (required for timeout) is not supported in sigchild environment');
}
/**
* {@inheritdoc}
*/
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
$process->setEnhanceSigchildCompatibility(true);
return $process;
}
}

View File

@ -1,216 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
use Symfony\Component\Process\Process;
class SimpleProcessTest extends AbstractProcessTest
{
private $enabledSigchild = false;
protected function setUp()
{
ob_start();
phpinfo(INFO_GENERAL);
$this->enabledSigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
}
public function testGetExitCode()
{
$this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case
parent::testGetExitCode();
}
public function testExitCodeCommandFailed()
{
$this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case
parent::testExitCodeCommandFailed();
}
public function testProcessIsSignaledIfStopped()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
parent::testProcessIsSignaledIfStopped();
}
public function testProcessWithTermSignal()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
parent::testProcessWithTermSignal();
}
public function testProcessIsNotSignaled()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
parent::testProcessIsNotSignaled();
}
public function testProcessWithoutTermSignal()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
parent::testProcessWithoutTermSignal();
}
public function testExitCodeText()
{
$this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case
parent::testExitCodeText();
}
public function testIsSuccessful()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testIsSuccessful();
}
public function testIsNotSuccessful()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testIsNotSuccessful();
}
public function testGetPid()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testGetPid();
}
public function testGetPidIsNullBeforeStart()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testGetPidIsNullBeforeStart();
}
public function testGetPidIsNullAfterRun()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testGetPidIsNullAfterRun();
}
public function testSignal()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
parent::testSignal();
}
public function testProcessWithoutTermSignalIsNotSignaled()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
parent::testProcessWithoutTermSignalIsNotSignaled();
}
public function testProcessThrowsExceptionWhenExternallySignaled()
{
$this->skipIfPHPSigchild(); // This test use PID that is not available in this case
parent::testProcessThrowsExceptionWhenExternallySignaled();
}
public function testExitCodeIsAvailableAfterSignal()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
parent::testExitCodeIsAvailableAfterSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\LogicException
* @expectedExceptionMessage Can not send signal on a non running process.
*/
public function testSignalProcessNotRunning()
{
parent::testSignalProcessNotRunning();
}
public function testSignalWithWrongIntSignal()
{
if ($this->enabledSigchild) {
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
} else {
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Error while sending signal `-4`.');
}
parent::testSignalWithWrongIntSignal();
}
public function testSignalWithWrongNonIntSignal()
{
if ($this->enabledSigchild) {
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
} else {
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Error while sending signal `Céphalopodes`.');
}
parent::testSignalWithWrongNonIntSignal();
}
public function testStopTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
$process->stop();
});
$this->assertTrue(true, 'A call to stop() is not expected to cause wait() to throw a RuntimeException');
}
public function testKillSignalTerminatesProcessCleanly()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(defined('SIGKILL') ? SIGKILL : 9);
}
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
public function testTermSignalTerminatesProcessCleanly()
{
$this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(defined('SIGTERM') ? SIGTERM : 15);
}
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
public function testStopWithTimeoutIsActuallyWorking()
{
$this->skipIfPHPSigchild();
parent::testStopWithTimeoutIsActuallyWorking();
}
/**
* {@inheritdoc}
*/
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
}
private function skipIfPHPSigchild()
{
if ($this->enabledSigchild) {
$this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed');
}
}
private function expectExceptionIfPHPSigchild($classname, $message)
{
if ($this->enabledSigchild) {
$this->setExpectedException($classname, $message);
}
}
}