package.xml 0000644 0000765 0000024 00000011475 12155624504 012316 0 ustar fabien staff
Processpear.symfony.comSymfony2 Process ComponentSymfony2 Process ComponentFabien Potencierfabpotfabien@symfony.comyes2013-06-112.3.12.3.1stablestableMIT
-
5.3.21.4.0
Process-2.3.1/Symfony/Component/Process/autoloader.php 0000644 0000765 0000024 00000000521 12155624504 022140 0 ustar fabien staff =5.3.3"
},
"autoload": {
"psr-0": { "Symfony\\Component\\Process\\": "" }
},
"target-dir": "Symfony/Component/Process",
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
}
}
Process-2.3.1/Symfony/Component/Process/Exception/ExceptionInterface.php 0000644 0000765 0000024 00000000657 12155624504 025530 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* Marker Interface for the Process Component.
*
* @author Johannes M. Schmitt
*/
interface ExceptionInterface
{
}
Process-2.3.1/Symfony/Component/Process/Exception/InvalidArgumentException.php 0000644 0000765 0000024 00000000760 12155624504 026714 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* InvalidArgumentException for the Process Component.
*
* @author Romain Neutron
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
Process-2.3.1/Symfony/Component/Process/Exception/LogicException.php 0000644 0000765 0000024 00000000722 12155624504 024656 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* LogicException for the Process Component.
*
* @author Romain Neutron
*/
class LogicException extends \LogicException implements ExceptionInterface
{
}
Process-2.3.1/Symfony/Component/Process/Exception/ProcessFailedException.php 0000644 0000765 0000024 00000002372 12155624504 026347 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
use Symfony\Component\Process\Process;
/**
* Exception for failed processes.
*
* @author Johannes M. Schmitt
*/
class ProcessFailedException extends RuntimeException
{
private $process;
public function __construct(Process $process)
{
if ($process->isSuccessful()) {
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
}
parent::__construct(
sprintf(
'The command "%s" failed.'."\nExit Code: %s(%s)\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
$process->getCommandLine(),
$process->getExitCode(),
$process->getExitCodeText(),
$process->getOutput(),
$process->getErrorOutput()
)
);
$this->process = $process;
}
public function getProcess()
{
return $this->process;
}
}
Process-2.3.1/Symfony/Component/Process/Exception/RuntimeException.php 0000644 0000765 0000024 00000000741 12155624504 025245 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* RuntimeException for the Process Component.
*
* @author Johannes M. Schmitt
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
Process-2.3.1/Symfony/Component/Process/ExecutableFinder.php 0000644 0000765 0000024 00000005025 12155624504 023216 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
/**
* Generic executable finder.
*
* @author Fabien Potencier
* @author Johannes M. Schmitt
*/
class ExecutableFinder
{
private $suffixes = array('.exe', '.bat', '.cmd', '.com');
/**
* Replaces default suffixes of executable.
*
* @param array $suffixes
*/
public function setSuffixes(array $suffixes)
{
$this->suffixes = $suffixes;
}
/**
* Adds new possible suffix to check for executable.
*
* @param string $suffix
*/
public function addSuffix($suffix)
{
$this->suffixes[] = $suffix;
}
/**
* Finds an executable by name.
*
* @param string $name The executable name (without the extension)
* @param string $default The default to return if no executable is found
* @param array $extraDirs Additional dirs to check into
*
* @return string The executable path or default value
*/
public function find($name, $default = null, array $extraDirs = array())
{
if (ini_get('open_basedir')) {
$searchPath = explode(PATH_SEPARATOR, getenv('open_basedir'));
$dirs = array();
foreach ($searchPath as $path) {
if (is_dir($path)) {
$dirs[] = $path;
} else {
$file = str_replace(dirname($path), '', $path);
if ($file == $name && is_executable($path)) {
return $path;
}
}
}
} else {
$dirs = array_merge(
explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
$extraDirs
);
}
$suffixes = array('');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$pathExt = getenv('PATHEXT');
$suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
}
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
return $file;
}
}
}
return $default;
}
}
Process-2.3.1/Symfony/Component/Process/LICENSE 0000644 0000765 0000024 00000002051 12155624504 020275 0 ustar fabien staff Copyright (c) 2004-2013 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Process-2.3.1/Symfony/Component/Process/PhpExecutableFinder.php 0000644 0000765 0000024 00000002720 12155624504 023665 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
/**
* An executable finder specifically designed for the PHP executable.
*
* @author Fabien Potencier
* @author Johannes M. Schmitt
*/
class PhpExecutableFinder
{
private $executableFinder;
public function __construct()
{
$this->executableFinder = new ExecutableFinder();
}
/**
* Finds The PHP executable.
*
* @return string|false The PHP executable path or false if it cannot be found
*/
public function find()
{
// PHP_BINARY return the current sapi executable
if (defined('PHP_BINARY') && PHP_BINARY && ('cli' === PHP_SAPI)) {
return PHP_BINARY;
}
if ($php = getenv('PHP_PATH')) {
if (!is_executable($php)) {
return false;
}
return $php;
}
if ($php = getenv('PHP_PEAR_PHP_BIN')) {
if (is_executable($php)) {
return $php;
}
}
$dirs = array(PHP_BINDIR);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$dirs[] = 'C:\xampp\php\\';
}
return $this->executableFinder->find('php', false, $dirs);
}
}
Process-2.3.1/Symfony/Component/Process/PhpProcess.php 0000644 0000765 0000024 00000003432 12155624504 022073 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\RuntimeException;
/**
* PhpProcess runs a PHP script in an independent process.
*
* $p = new PhpProcess('');
* $p->run();
* print $p->getOutput()."\n";
*
* @author Fabien Potencier
*
* @api
*/
class PhpProcess extends Process
{
private $executableFinder;
/**
* Constructor.
*
* @param string $script The PHP script to run (as a string)
* @param string $cwd The working directory
* @param array $env The environment variables
* @param integer $timeout The timeout in seconds
* @param array $options An array of options for proc_open
*
* @api
*/
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
{
parent::__construct(null, $cwd, $env, $script, $timeout, $options);
$this->executableFinder = new PhpExecutableFinder();
}
/**
* Sets the path to the PHP binary to use.
*
* @api
*/
public function setPhpBinary($php)
{
$this->setCommandLine($php);
}
/**
* {@inheritdoc}
*/
public function start($callback = null)
{
if (null === $this->getCommandLine()) {
if (false === $php = $this->executableFinder->find()) {
throw new RuntimeException('Unable to find the PHP executable.');
}
$this->setCommandLine($php);
}
parent::start($callback);
}
}
Process-2.3.1/Symfony/Component/Process/phpunit.xml.dist 0000644 0000765 0000024 00000001406 12155624504 022446 0 ustar fabien staff
./Tests/././Tests
Process-2.3.1/Symfony/Component/Process/Process.php 0000644 0000765 0000024 00000107437 12155624504 021435 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
/**
* Process is a thin wrapper around proc_* functions to ease
* start independent PHP processes.
*
* @author Fabien Potencier
*
* @api
*/
class Process
{
const ERR = 'err';
const OUT = 'out';
const STATUS_READY = 'ready';
const STATUS_STARTED = 'started';
const STATUS_TERMINATED = 'terminated';
const STDIN = 0;
const STDOUT = 1;
const STDERR = 2;
// Timeout Precision in seconds.
const TIMEOUT_PRECISION = 0.2;
private $commandline;
private $cwd;
private $env;
private $stdin;
private $starttime;
private $timeout;
private $options;
private $exitcode;
private $fallbackExitcode;
private $processInformation;
private $stdout;
private $stderr;
private $enhanceWindowsCompatibility;
private $enhanceSigchildCompatibility;
private $pipes;
private $process;
private $status = self::STATUS_READY;
private $incrementalOutputOffset;
private $incrementalErrorOutputOffset;
private $tty;
private $fileHandles;
private $readBytes;
private static $sigchild;
/**
* Exit codes translation table.
*
* User-defined errors must use exit codes in the 64-113 range.
*
* @var array
*/
public static $exitCodes = array(
0 => 'OK',
1 => 'General error',
2 => 'Misuse of shell builtins',
126 => 'Invoked command cannot execute',
127 => 'Command not found',
128 => 'Invalid exit argument',
// signals
129 => 'Hangup',
130 => 'Interrupt',
131 => 'Quit and dump core',
132 => 'Illegal instruction',
133 => 'Trace/breakpoint trap',
134 => 'Process aborted',
135 => 'Bus error: "access to undefined portion of memory object"',
136 => 'Floating point exception: "erroneous arithmetic operation"',
137 => 'Kill (terminate immediately)',
138 => 'User-defined 1',
139 => 'Segmentation violation',
140 => 'User-defined 2',
141 => 'Write to pipe with no one reading',
142 => 'Signal raised by alarm',
143 => 'Termination (request to terminate)',
// 144 - not defined
145 => 'Child process terminated, stopped (or continued*)',
146 => 'Continue if stopped',
147 => 'Stop executing temporarily',
148 => 'Terminal stop signal',
149 => 'Background process attempting to read from tty ("in")',
150 => 'Background process attempting to write to tty ("out")',
151 => 'Urgent data available on socket',
152 => 'CPU time limit exceeded',
153 => 'File size limit exceeded',
154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
155 => 'Profiling timer expired',
// 156 - not defined
157 => 'Pollable event',
// 158 - not defined
159 => 'Bad syscall',
);
/**
* Constructor.
*
* @param string $commandline The command line to run
* @param string $cwd The working directory
* @param array $env The environment variables or null to inherit
* @param string $stdin The STDIN content
* @param integer $timeout The timeout in seconds
* @param array $options An array of options for proc_open
*
* @throws RuntimeException When proc_open is not installed
*
* @api
*/
public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
if (!function_exists('proc_open')) {
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
}
$this->commandline = $commandline;
$this->cwd = $cwd;
// on windows, if the cwd changed via chdir(), proc_open defaults to the dir where php was started
// on gnu/linux, PHP builds with --enable-maintainer-zts are also affected
// @see : https://bugs.php.net/bug.php?id=51800
// @see : https://bugs.php.net/bug.php?id=50524
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
$this->cwd = getcwd();
}
if (null !== $env) {
$this->env = array();
foreach ($env as $key => $value) {
$this->env[(binary) $key] = (binary) $value;
}
} else {
$this->env = null;
}
$this->stdin = $stdin;
$this->setTimeout($timeout);
$this->enhanceWindowsCompatibility = true;
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
}
public function __destruct()
{
// stop() will check if we have a process running.
$this->stop();
}
public function __clone()
{
$this->exitcode = null;
$this->fallbackExitcode = null;
$this->processInformation = null;
$this->stdout = null;
$this->stderr = null;
$this->pipes = null;
$this->process = null;
$this->status = self::STATUS_READY;
$this->fileHandles = null;
$this->readBytes = null;
}
/**
* Runs the process.
*
* The callback receives the type of output (out or err) and
* some bytes from the output in real-time. It allows to have feedback
* from the independent process during execution.
*
* The STDOUT and STDERR are also available after the process is finished
* via the getOutput() and getErrorOutput() methods.
*
* @param callback|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return integer The exit status code
*
* @throws RuntimeException When process can't be launch or is stopped
*
* @api
*/
public function run($callback = null)
{
$this->start($callback);
return $this->wait($callback);
}
/**
* Starts the process and returns after sending the STDIN.
*
* This method blocks until all STDIN data is sent to the process then it
* returns while the process runs in the background.
*
* The termination of the process can be awaited with wait().
*
* The callback receives the type of output (out or err) and some bytes from
* the output in real-time while writing the standard input to the process.
* It allows to have feedback from the independent process during execution.
* If there is no callback passed, the wait() method can be called
* with true as a second parameter then the callback will get all data occurred
* in (and since) the start call.
*
* @param callback|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @throws RuntimeException When process can't be launch or is stopped
* @throws RuntimeException When process is already running
*/
public function start($callback = null)
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
}
$this->starttime = microtime(true);
$this->stdout = '';
$this->stderr = '';
$this->incrementalOutputOffset = 0;
$this->incrementalErrorOutputOffset = 0;
$callback = $this->buildCallback($callback);
$descriptors = $this->getDescriptors();
$commandline = $this->commandline;
if (defined('PHP_WINDOWS_VERSION_BUILD') && $this->enhanceWindowsCompatibility) {
$commandline = 'cmd /V:ON /E:ON /C "'.$commandline.'"';
if (!isset($this->options['bypass_shell'])) {
$this->options['bypass_shell'] = true;
}
}
$this->process = proc_open($commandline, $descriptors, $this->pipes, $this->cwd, $this->env, $this->options);
if (!is_resource($this->process)) {
throw new RuntimeException('Unable to launch a new process.');
}
$this->status = self::STATUS_STARTED;
foreach ($this->pipes as $pipe) {
stream_set_blocking($pipe, false);
}
if ($this->tty) {
$this->status = self::STATUS_TERMINATED;
return;
}
if (null === $this->stdin) {
fclose($this->pipes[0]);
unset($this->pipes[0]);
return;
}
$writePipes = array($this->pipes[0]);
unset($this->pipes[0]);
$stdinLen = strlen($this->stdin);
$stdinOffset = 0;
while ($writePipes) {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->processFileHandles($callback);
}
$r = $this->pipes;
$w = $writePipes;
$e = null;
$n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6));
if (false === $n) {
break;
}
if ($n === 0) {
proc_terminate($this->process);
throw new RuntimeException('The process timed out.');
}
if ($w) {
$written = fwrite($writePipes[0], (binary) substr($this->stdin, $stdinOffset), 8192);
if (false !== $written) {
$stdinOffset += $written;
}
if ($stdinOffset >= $stdinLen) {
fclose($writePipes[0]);
$writePipes = null;
}
}
foreach ($r as $pipe) {
$type = array_search($pipe, $this->pipes);
$data = fread($pipe, 8192);
if (strlen($data) > 0) {
call_user_func($callback, $type == 1 ? self::OUT : self::ERR, $data);
}
if (false === $data || feof($pipe)) {
fclose($pipe);
unset($this->pipes[$type]);
}
}
$this->checkTimeout();
}
$this->updateStatus();
}
/**
* Restarts the process.
*
* Be warned that the process is cloned before being started.
*
* @param callable $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return Process The new process
*
* @throws \RuntimeException When process can't be launch or is stopped
* @throws \RuntimeException When process is already running
*
* @see start()
*/
public function restart($callback = null)
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
}
$process = clone $this;
$process->start($callback);
return $process;
}
/**
* Waits for the process to terminate.
*
* The callback receives the type of output (out or err) and some bytes
* from the output in real-time while writing the standard input to the process.
* It allows to have feedback from the independent process during execution.
*
* @param callback|null $callback A valid PHP callback
*
* @return integer The exitcode of the process
*
* @throws \RuntimeException When process timed out
* @throws \RuntimeException When process stopped after receiving signal
*/
public function wait($callback = null)
{
$this->updateStatus();
$callback = $this->buildCallback($callback);
while ($this->pipes || (defined('PHP_WINDOWS_VERSION_BUILD') && $this->fileHandles)) {
if (defined('PHP_WINDOWS_VERSION_BUILD') && $this->fileHandles) {
$this->processFileHandles($callback, !$this->pipes);
}
$this->checkTimeout();
if ($this->pipes) {
$r = $this->pipes;
$w = null;
$e = null;
// let's have a look if something changed in streams
if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) {
$lastError = error_get_last();
// stream_select returns false when the `select` system call is interrupted by an incoming signal
if (isset($lastError['message']) && false === stripos($lastError['message'], 'interrupted system call')) {
$this->pipes = array();
}
continue;
}
// nothing has changed
if (0 === $n) {
continue;
}
foreach ($r as $pipe) {
$type = array_search($pipe, $this->pipes);
$data = fread($pipe, 8192);
if (strlen($data) > 0) {
// last exit code is output and caught to work around --enable-sigchild
if (3 == $type) {
$this->fallbackExitcode = (int) $data;
} else {
call_user_func($callback, $type == 1 ? self::OUT : self::ERR, $data);
}
}
if (false === $data || feof($pipe)) {
fclose($pipe);
unset($this->pipes[$type]);
}
}
}
}
$this->updateStatus();
if ($this->processInformation['signaled']) {
if ($this->isSigchildEnabled()) {
throw new RuntimeException('The process has been signaled.');
}
throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
}
$time = 0;
while ($this->isRunning() && $time < 1000000) {
$time += 1000;
usleep(1000);
}
$exitcode = proc_close($this->process);
if ($this->processInformation['signaled']) {
if ($this->isSigchildEnabled()) {
throw new RuntimeException('The process has been signaled.');
}
throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
}
$this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
if (-1 == $this->exitcode && null !== $this->fallbackExitcode) {
$this->exitcode = $this->fallbackExitcode;
}
return $this->exitcode;
}
/**
* Returns the Pid (process identifier), if applicable.
*
* @return integer|null The process id if running, null otherwise
*
* @throws RuntimeException In case --enable-sigchild is activated
*/
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();
return $this->isRunning() ? $this->processInformation['pid'] : null;
}
/**
* Sends a posix signal to the process.
*
* @param integer $signal A valid posix signal (see http://www.php.net/manual/en/pcntl.constants.php)
* @return Process
*
* @throws LogicException In case the process is not running
* @throws RuntimeException In case --enable-sigchild is activated
* @throws RuntimeException In case of failure
*/
public function signal($signal)
{
if (!$this->isRunning()) {
throw new LogicException('Can not send signal on a non running process.');
}
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
}
if (true !== @proc_terminate($this->process, $signal)) {
throw new RuntimeException(sprintf('Error while sending signal `%d`.', $signal));
}
return $this;
}
/**
* Returns the current output of the process (STDOUT).
*
* @return string The process output
*
* @api
*/
public function getOutput()
{
$this->updateOutput();
return $this->stdout;
}
/**
* Returns the output incrementally.
*
* In comparison with the getOutput method which always return the whole
* output, this one returns the new output since the last call.
*
* @return string The process output since the last call
*/
public function getIncrementalOutput()
{
$data = $this->getOutput();
$latest = substr($data, $this->incrementalOutputOffset);
$this->incrementalOutputOffset = strlen($data);
return $latest;
}
/**
* Returns the current error output of the process (STDERR).
*
* @return string The process error output
*
* @api
*/
public function getErrorOutput()
{
$this->updateErrorOutput();
return $this->stderr;
}
/**
* Returns the errorOutput incrementally.
*
* In comparison with the getErrorOutput method which always return the
* whole error output, this one returns the new error output since the last
* call.
*
* @return string The process error output since the last call
*/
public function getIncrementalErrorOutput()
{
$data = $this->getErrorOutput();
$latest = substr($data, $this->incrementalErrorOutputOffset);
$this->incrementalErrorOutputOffset = strlen($data);
return $latest;
}
/**
* Returns the exit code returned by the process.
*
* @return integer The exit status code
*
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
*
* @api
*/
public function getExitCode()
{
if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method');
}
$this->updateStatus();
return $this->exitcode;
}
/**
* Returns a string representation for the exit code returned by the process.
*
* This method relies on the Unix exit code status standardization
* and might not be relevant for other operating systems.
*
* @return string A string representation for the exit status code
*
* @see http://tldp.org/LDP/abs/html/exitcodes.html
* @see http://en.wikipedia.org/wiki/Unix_signal
*/
public function getExitCodeText()
{
$exitcode = $this->getExitCode();
return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
}
/**
* Checks if the process ended successfully.
*
* @return Boolean true if the process ended successfully, false otherwise
*
* @api
*/
public function isSuccessful()
{
return 0 == $this->getExitCode();
}
/**
* Returns true if the child process has been terminated by an uncaught signal.
*
* It always returns false on Windows.
*
* @return Boolean
*
* @throws RuntimeException In case --enable-sigchild is activated
*
* @api
*/
public function hasBeenSignaled()
{
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
}
$this->updateStatus();
return $this->processInformation['signaled'];
}
/**
* Returns the number of the signal that caused the child process to terminate its execution.
*
* It is only meaningful if hasBeenSignaled() returns true.
*
* @return integer
*
* @throws RuntimeException In case --enable-sigchild is activated
*
* @api
*/
public function getTermSignal()
{
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
}
$this->updateStatus();
return $this->processInformation['termsig'];
}
/**
* Returns true if the child process has been stopped by a signal.
*
* It always returns false on Windows.
*
* @return Boolean
*
* @api
*/
public function hasBeenStopped()
{
$this->updateStatus();
return $this->processInformation['stopped'];
}
/**
* Returns the number of the signal that caused the child process to stop its execution.
*
* It is only meaningful if hasBeenStopped() returns true.
*
* @return integer
*
* @api
*/
public function getStopSignal()
{
$this->updateStatus();
return $this->processInformation['stopsig'];
}
/**
* Checks if the process is currently running.
*
* @return Boolean true if the process is currently running, false otherwise
*/
public function isRunning()
{
if (self::STATUS_STARTED !== $this->status) {
return false;
}
$this->updateStatus();
return $this->processInformation['running'];
}
/**
* Checks if the process has been started with no regard to the current state.
*
* @return Boolean true if status is ready, false otherwise
*/
public function isStarted()
{
return $this->status != self::STATUS_READY;
}
/**
* Checks if the process is terminated.
*
* @return Boolean true if process is terminated, false otherwise
*/
public function isTerminated()
{
$this->updateStatus();
return $this->status == self::STATUS_TERMINATED;
}
/**
* Gets the process status.
*
* The status is one of: ready, started, terminated.
*
* @return string The current process status
*/
public function getStatus()
{
$this->updateStatus();
return $this->status;
}
/**
* Stops the process.
*
* @param integer|float $timeout The timeout in seconds
* @param integer $signal A posix signal to send in case the process has not stop at timeout, default is SIGKILL
*
* @return integer The exit-code of the process
*
* @throws RuntimeException if the process got signaled
*/
public function stop($timeout = 10, $signal = null)
{
$timeoutMicro = (int) $timeout*1E6;
if ($this->isRunning()) {
proc_terminate($this->process);
$time = 0;
while (1 == $this->isRunning() && $time < $timeoutMicro) {
$time += 1000;
usleep(1000);
}
if ($this->isRunning() && !$this->isSigchildEnabled()) {
if (null !== $signal || defined('SIGKILL')) {
$this->signal($signal ?: SIGKILL);
}
}
foreach ($this->pipes as $pipe) {
fclose($pipe);
}
$this->pipes = array();
$exitcode = proc_close($this->process);
$this->exitcode = -1 === $this->processInformation['exitcode'] ? $exitcode : $this->processInformation['exitcode'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
foreach ($this->fileHandles as $fileHandle) {
fclose($fileHandle);
}
$this->fileHandles = array();
}
}
$this->status = self::STATUS_TERMINATED;
return $this->exitcode;
}
/**
* Adds a line to the STDOUT stream.
*
* @param string $line The line to append
*/
public function addOutput($line)
{
$this->stdout .= $line;
}
/**
* Adds a line to the STDERR stream.
*
* @param string $line The line to append
*/
public function addErrorOutput($line)
{
$this->stderr .= $line;
}
/**
* Gets the command line to be executed.
*
* @return string The command to execute
*/
public function getCommandLine()
{
return $this->commandline;
}
/**
* Sets the command line to be executed.
*
* @param string $commandline The command to execute
*
* @return self The current Process instance
*/
public function setCommandLine($commandline)
{
$this->commandline = $commandline;
return $this;
}
/**
* Gets the process timeout.
*
* @return integer|null The timeout in seconds or null if it's disabled
*/
public function getTimeout()
{
return $this->timeout;
}
/**
* Sets the process timeout.
*
* To disable the timeout, set this value to null.
*
* @param float|null $timeout The timeout in seconds
*
* @return self The current Process instance
*
* @throws InvalidArgumentException if the timeout is negative
*/
public function setTimeout($timeout)
{
if (null === $timeout) {
$this->timeout = null;
return $this;
}
$timeout = (float) $timeout;
if ($timeout < 0) {
throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
}
$this->timeout = $timeout;
return $this;
}
/**
* Enables or disables the TTY mode.
*
* @param boolean $tty True to enabled and false to disable
*
* @return self The current Process instance
*/
public function setTty($tty)
{
$this->tty = (Boolean) $tty;
return $this;
}
/**
* Checks if the TTY mode is enabled.
*
* @return Boolean true if the TTY mode is enabled, false otherwise
*/
public function isTty()
{
return $this->tty;
}
/**
* Gets the working directory.
*
* @return string The current working directory
*/
public function getWorkingDirectory()
{
// This is for BC only
if (null === $this->cwd) {
// getcwd() will return false if any one of the parent directories does not have
// the readable or search mode set, even if the current directory does
return getcwd() ?: null;
}
return $this->cwd;
}
/**
* Sets the current working directory.
*
* @param string $cwd The new working directory
*
* @return self The current Process instance
*/
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;
return $this;
}
/**
* Gets the environment variables.
*
* @return array The current environment variables
*/
public function getEnv()
{
return $this->env;
}
/**
* Sets the environment variables.
*
* @param array $env The new environment variables
*
* @return self The current Process instance
*/
public function setEnv(array $env)
{
$this->env = $env;
return $this;
}
/**
* Gets the contents of STDIN.
*
* @return string The current contents
*/
public function getStdin()
{
return $this->stdin;
}
/**
* Sets the contents of STDIN.
*
* @param string $stdin The new contents
*
* @return self The current Process instance
*/
public function setStdin($stdin)
{
$this->stdin = $stdin;
return $this;
}
/**
* Gets the options for proc_open.
*
* @return array The current options
*/
public function getOptions()
{
return $this->options;
}
/**
* Sets the options for proc_open.
*
* @param array $options The new options
*
* @return self The current Process instance
*/
public function setOptions(array $options)
{
$this->options = $options;
return $this;
}
/**
* Gets whether or not Windows compatibility is enabled.
*
* This is true by default.
*
* @return Boolean
*/
public function getEnhanceWindowsCompatibility()
{
return $this->enhanceWindowsCompatibility;
}
/**
* Sets whether or not Windows compatibility is enabled.
*
* @param Boolean $enhance
*
* @return self The current Process instance
*/
public function setEnhanceWindowsCompatibility($enhance)
{
$this->enhanceWindowsCompatibility = (Boolean) $enhance;
return $this;
}
/**
* Returns whether sigchild compatibility mode is activated or not.
*
* @return Boolean
*/
public function getEnhanceSigchildCompatibility()
{
return $this->enhanceSigchildCompatibility;
}
/**
* Activates sigchild compatibility mode.
*
* Sigchild compatibility mode is required to get the exit code and
* determine the success of a process when PHP has been compiled with
* the --enable-sigchild option
*
* @param Boolean $enhance
*
* @return self The current Process instance
*/
public function setEnhanceSigchildCompatibility($enhance)
{
$this->enhanceSigchildCompatibility = (Boolean) $enhance;
return $this;
}
/**
* Performs a check between the timeout definition and the time the process started.
*
* In case you run a background process (with the start method), you should
* trigger this method regularly to ensure the process timeout
*
* @throws RuntimeException In case the timeout was reached
*/
public function checkTimeout()
{
if (0 < $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
$this->stop(0);
throw new RuntimeException('The process timed-out.');
}
}
/**
* Creates the descriptors needed by the proc_open.
*
* @return array
*/
private function getDescriptors()
{
//Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
//Workaround for this problem is to use temporary files instead of pipes on Windows platform.
//@see https://bugs.php.net/bug.php?id=51800
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->fileHandles = array(
self::STDOUT => tmpfile(),
);
if (false === $this->fileHandles[self::STDOUT]) {
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
}
$this->readBytes = array(
self::STDOUT => 0,
);
return array(array('pipe', 'r'), $this->fileHandles[self::STDOUT], array('pipe', 'w'));
}
if ($this->tty) {
$descriptors = array(
array('file', '/dev/tty', 'r'),
array('file', '/dev/tty', 'w'),
array('file', '/dev/tty', 'w'),
);
} else {
$descriptors = array(
array('pipe', 'r'), // stdin
array('pipe', 'w'), // stdout
array('pipe', 'w'), // stderr
);
}
if ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors = array_merge($descriptors, array(array('pipe', 'w')));
$this->commandline = '('.$this->commandline.') 3>/dev/null; code=$?; echo $code >&3; exit $code';
}
return $descriptors;
}
/**
* Builds up the callback used by wait().
*
* The callbacks adds all occurred output to the specific buffer and calls
* the user callback (if present) with the received output.
*
* @param callback|null $callback The user defined PHP callback
*
* @return callback A PHP callable
*/
protected function buildCallback($callback)
{
$that = $this;
$out = self::OUT;
$err = self::ERR;
$callback = function ($type, $data) use ($that, $callback, $out, $err) {
if ($out == $type) {
$that->addOutput($data);
} else {
$that->addErrorOutput($data);
}
if (null !== $callback) {
call_user_func($callback, $type, $data);
}
};
return $callback;
}
/**
* Updates the status of the process.
*/
protected function updateStatus()
{
if (self::STATUS_STARTED !== $this->status) {
return;
}
$this->processInformation = proc_get_status($this->process);
if (!$this->processInformation['running']) {
$this->status = self::STATUS_TERMINATED;
if (-1 !== $this->processInformation['exitcode']) {
$this->exitcode = $this->processInformation['exitcode'];
}
}
}
/**
* Updates the current error output of the process (STDERR).
*/
protected function updateErrorOutput()
{
if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
$this->addErrorOutput(stream_get_contents($this->pipes[self::STDERR]));
}
}
/**
* Updates the current output of the process (STDOUT).
*/
protected function updateOutput()
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && isset($this->fileHandles[self::STDOUT]) && is_resource($this->fileHandles[self::STDOUT])) {
fseek($this->fileHandles[self::STDOUT], $this->readBytes[self::STDOUT]);
$this->addOutput(stream_get_contents($this->fileHandles[self::STDOUT]));
} elseif (isset($this->pipes[self::STDOUT]) && is_resource($this->pipes[self::STDOUT])) {
$this->addOutput(stream_get_contents($this->pipes[self::STDOUT]));
}
}
/**
* Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
*
* @return Boolean
*/
protected function isSigchildEnabled()
{
if (null !== self::$sigchild) {
return self::$sigchild;
}
ob_start();
phpinfo(INFO_GENERAL);
return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
}
/**
* Handles the windows file handles fallbacks.
*
* @param callable $callback A valid PHP callback
* @param Boolean $closeEmptyHandles if true, handles that are empty will be assumed closed
*/
private function processFileHandles($callback, $closeEmptyHandles = false)
{
$fh = $this->fileHandles;
foreach ($fh as $type => $fileHandle) {
fseek($fileHandle, $this->readBytes[$type]);
$data = fread($fileHandle, 8192);
if (strlen($data) > 0) {
$this->readBytes[$type] += strlen($data);
call_user_func($callback, $type == 1 ? self::OUT : self::ERR, $data);
}
if (false === $data || ($closeEmptyHandles && '' === $data && feof($fileHandle))) {
fclose($fileHandle);
unset($this->fileHandles[$type]);
}
}
}
}
Process-2.3.1/Symfony/Component/Process/ProcessBuilder.php 0000644 0000765 0000024 00000007330 12155624504 022733 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
/**
* Process builder.
*
* @author Kris Wallsmith
*/
class ProcessBuilder
{
private $arguments;
private $cwd;
private $env;
private $stdin;
private $timeout;
private $options;
private $inheritEnv;
private $prefix;
public function __construct(array $arguments = array())
{
$this->arguments = $arguments;
$this->timeout = 60;
$this->options = array();
$this->env = array();
$this->inheritEnv = true;
}
public static function create(array $arguments = array())
{
return new static($arguments);
}
/**
* Adds an unescaped argument to the command string.
*
* @param string $argument A command argument
*
* @return ProcessBuilder
*/
public function add($argument)
{
$this->arguments[] = $argument;
return $this;
}
/**
* Adds an unescaped prefix to the command string.
*
* The prefix is preserved when reseting arguments.
*
* @param string $prefix A command prefix
*
* @return ProcessBuilder
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
return $this;
}
/**
* @param array $arguments
*
* @return ProcessBuilder
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;
return $this;
}
public function inheritEnvironmentVariables($inheritEnv = true)
{
$this->inheritEnv = $inheritEnv;
return $this;
}
public function setEnv($name, $value)
{
$this->env[$name] = $value;
return $this;
}
public function setInput($stdin)
{
$this->stdin = $stdin;
return $this;
}
/**
* Sets the process timeout.
*
* To disable the timeout, set this value to null.
*
* @param float|null
*
* @return ProcessBuilder
*
* @throws InvalidArgumentException
*/
public function setTimeout($timeout)
{
if (null === $timeout) {
$this->timeout = null;
return $this;
}
$timeout = (float) $timeout;
if ($timeout < 0) {
throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
}
$this->timeout = $timeout;
return $this;
}
public function setOption($name, $value)
{
$this->options[$name] = $value;
return $this;
}
public function getProcess()
{
if (!$this->prefix && !count($this->arguments)) {
throw new LogicException('You must add() command arguments before calling getProcess().');
}
$options = $this->options;
$arguments = $this->prefix ? array_merge(array($this->prefix), $this->arguments) : $this->arguments;
$script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
if ($this->inheritEnv) {
$env = $this->env ? $this->env + $_ENV : null;
} else {
$env = $this->env;
}
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
}
}
Process-2.3.1/Symfony/Component/Process/ProcessUtils.php 0000644 0000765 0000024 00000003243 12155624504 022444 0 ustar fabien staff
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
/**
* ProcessUtils is a bunch of utility methods.
*
* This class contains static methods only and is not meant to be instantiated.
*
* @author Martin Hasoň
*/
class ProcessUtils
{
/**
* This class should not be instantiated
*/
private function __construct()
{
}
/**
* Escapes a string to be used as a shell argument.
*
* @param string $argument The argument that will be escaped
*
* @return string The escaped argument
*/
public static function escapeArgument($argument)
{
//Fix for PHP bug #43784 escapeshellarg removes % from given string
//Fix for PHP bug #49446 escapeshellarg dosn`t work on windows
//@see https://bugs.php.net/bug.php?id=43784
//@see https://bugs.php.net/bug.php?id=49446
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$escapedArgument = '';
foreach(preg_split('/([%"])/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' == $part) {
$escapedArgument .= '\\"';
} elseif ('%' == $part) {
$escapedArgument .= '^%';
} else {
$escapedArgument .= escapeshellarg($part);
}
}
return $escapedArgument;
}
return escapeshellarg($argument);
}
}
Process-2.3.1/Symfony/Component/Process/README.md 0000644 0000765 0000024 00000002520 12155624504 020550 0 ustar fabien staff Process Component
=================
Process executes commands in sub-processes.
In this example, we run a simple directory listing and get the result back:
use Symfony\Component\Process\Process;
$process = new Process('ls -lsa');
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeException($process->getErrorOutput());
}
print $process->getOutput();
You can think that this is easy to achieve with plain PHP but it's not especially
if you want to take care of the subtle differences between the different platforms.
And if you want to be able to get some feedback in real-time, just pass an
anonymous function to the ``run()`` method and you will get the output buffer
as it becomes available:
use Symfony\Component\Process\Process;
$process = new Process('ls -lsa');
$process->run(function ($type, $buffer) {
if ('err' === $type) {
echo 'ERR > '.$buffer;
} else {
echo 'OUT > '.$buffer;
}
});
That's great if you want to execute a long running command (like rsync-ing files to a
remote server) and give feedback to the user in real-time.
Resources
---------
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/XXX/
$ composer.phar install --dev
$ phpunit
Process-2.3.1/Symfony/Component/Process/Tests/AbstractProcessTest.php 0000644 0000765 0000024 00000042410 12155624504 025050 0 ustar fabien staff
*
* 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;
use Symfony\Component\Process\Exception\RuntimeException;
/**
* @author Robert Schönthal
*/
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromConstructor()
{
$this->getProcess('', null, null, null, -1);
}
/**
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromSetter()
{
$p = $this->getProcess('');
$p->setTimeout(-1);
}
public function testNullTimeout()
{
$p = $this->getProcess('');
$p->setTimeout(10);
$p->setTimeout(null);
$this->assertNull($p->getTimeout());
}
public function testStopWithTimeoutIsActuallyWorking()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Stop with timeout does not work on windows, it requires posix signals');
}
// exec is mandatory here since we send a signal to the process
// see https://github.com/symfony/symfony/issues/5030 about prepending
// command with exec
$p = $this->getProcess('exec php '.__DIR__.'/NonStopableProcess.php 3');
$p->start();
usleep(100000);
$start = microtime(true);
$p->stop(1.1, SIGKILL);
while ($p->isRunning()) {
usleep(1000);
}
$duration = microtime(true) - $start;
$this->assertLessThan(1.3, $duration);
}
/**
* tests results from sub processes
*
* @dataProvider responsesCodeProvider
*/
public function testProcessResponses($expected, $getter, $code)
{
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
$p->run();
$this->assertSame($expected, $p->$getter());
}
/**
* tests results from sub processes
*
* @dataProvider pipesCodeProvider
*/
public function testProcessPipes($code, $size)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 and https://bugs.php.net/bug.php?id=51800');
}
$expected = str_repeat(str_repeat('*', 1024), $size) . '!';
$expectedLength = (1024 * $size) + 1;
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
$p->setStdin($expected);
$p->run();
$this->assertEquals($expectedLength, strlen($p->getOutput()));
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
}
public function chainedCommandsOutputProvider()
{
return array(
array("1\n1\n", ';', '1'),
array("2\n2\n", '&&', '2'),
);
}
/**
*
* @dataProvider chainedCommandsOutputProvider
*/
public function testChainedCommandsOutput($expected, $operator, $input)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Does it work on windows ?');
}
$process = $this->getProcess(sprintf('echo %s %s echo %s', $input, $operator, $input));
$process->run();
$this->assertEquals($expected, $process->getOutput());
}
public function testCallbackIsExecutedForOutput()
{
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg('echo \'foo\';')));
$called = false;
$p->run(function ($type, $buffer) use (&$called) {
$called = $buffer === 'foo';
});
$this->assertTrue($called, 'The callback should be executed with the output');
}
public function testGetErrorOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
$p->run();
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
}
public function testGetIncrementalErrorOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { usleep(50000); file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
$p->start();
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalErrorOutput(), $matches));
usleep(20000);
}
}
public function testGetOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
$p->run();
$this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
}
public function testGetIncrementalOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) { echo \' foo \'; usleep(50000); $n++; }')));
$p->start();
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
usleep(20000);
}
}
public function testExitCodeCommandFailed()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX exit code');
}
// such command run in bash return an exitcode 127
$process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
$process->run();
$this->assertGreaterThan(0, $process->getExitCode());
}
public function testTTYCommand()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does have /dev/tty support');
}
$process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTTY(true);
$process->run();
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
}
public function testExitCodeText()
{
$process = $this->getProcess('');
$r = new \ReflectionObject($process);
$p = $r->getProperty('exitcode');
$p->setAccessible(true);
$p->setValue($process, 2);
$this->assertEquals('Misuse of shell builtins', $process->getExitCodeText());
}
public function testStartIsNonBlocking()
{
$process = $this->getProcess('php -r "sleep(4);"');
$start = microtime(true);
$process->start();
$end = microtime(true);
$this->assertLessThan(1 , $end-$start);
}
public function testUpdateStatus()
{
$process = $this->getProcess('php -h');
$process->run();
$this->assertTrue(strlen($process->getOutput()) > 0);
}
public function testGetExitCode()
{
$process = $this->getProcess('php -m');
$process->run();
$this->assertEquals(0, $process->getExitCode());
}
public function testStatus()
{
$process = $this->getProcess('php -r "usleep(500000);"');
$this->assertFalse($process->isRunning());
$this->assertFalse($process->isStarted());
$this->assertFalse($process->isTerminated());
$this->assertSame(Process::STATUS_READY, $process->getStatus());
$process->start();
$this->assertTrue($process->isRunning());
$this->assertTrue($process->isStarted());
$this->assertFalse($process->isTerminated());
$this->assertSame(Process::STATUS_STARTED, $process->getStatus());
$process->wait();
$this->assertFalse($process->isRunning());
$this->assertTrue($process->isStarted());
$this->assertTrue($process->isTerminated());
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
}
public function testStop()
{
$process = $this->getProcess('php -r "while (true) {}"');
$process->start();
$this->assertTrue($process->isRunning());
$process->stop();
$this->assertFalse($process->isRunning());
}
public function testIsSuccessful()
{
$process = $this->getProcess('php -m');
$process->run();
$this->assertTrue($process->isSuccessful());
}
public function testIsNotSuccessful()
{
$process = $this->getProcess('php -r "while (true) {}"');
$process->start();
$this->assertTrue($process->isRunning());
$process->stop();
$this->assertFalse($process->isSuccessful());
}
public function testProcessIsNotSignaled()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$process = $this->getProcess('php -m');
$process->run();
$this->assertFalse($process->hasBeenSignaled());
}
public function testProcessWithoutTermSignalIsNotSignaled()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$process = $this->getProcess('php -m');
$process->run();
$this->assertFalse($process->hasBeenSignaled());
}
public function testProcessWithoutTermSignal()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$process = $this->getProcess('php -m');
$process->run();
$this->assertEquals(0, $process->getTermSignal());
}
public function testProcessIsSignaledIfStopped()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$process = $this->getProcess('php -r "while (true) {}"');
$process->start();
$process->stop();
$this->assertTrue($process->hasBeenSignaled());
}
public function testProcessWithTermSignal()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
// SIGTERM is only defined if pcntl extension is present
$termSignal = defined('SIGTERM') ? SIGTERM : 15;
$process = $this->getProcess('php -r "while (true) {}"');
$process->start();
$process->stop();
$this->assertEquals($termSignal, $process->getTermSignal());
}
public function testProcessThrowsExceptionWhenExternallySignaled()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
if (!function_exists('posix_kill')) {
$this->markTestSkipped('posix_kill is required for this test');
}
$termSignal = defined('SIGKILL') ? SIGKILL : 9;
$process = $this->getProcess('exec php -r "while (true) {}"');
$process->start();
posix_kill($process->getPid(), $termSignal);
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'The process has been signaled with signal "9".');
$process->wait();
}
public function testRestart()
{
$process1 = $this->getProcess('php -r "echo getmypid();"');
$process1->run();
$process2 = $process1->restart();
usleep(300000); // wait for output
// Ensure that both processed finished and the output is numeric
$this->assertFalse($process1->isRunning());
$this->assertFalse($process2->isRunning());
$this->assertTrue(is_numeric($process1->getOutput()));
$this->assertTrue(is_numeric($process2->getOutput()));
// Ensure that restart returned a new process by check that the output is different
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
}
public function testPhpDeadlock()
{
$this->markTestSkipped('Can course php to hang');
// Sleep doesn't work as it will allow the process to handle signals and close
// file handles from the other end.
$process = $this->getProcess('php -r "while (true) {}"');
$process->start();
// PHP will deadlock when it tries to cleanup $process
}
public function testRunProcessWithTimeout()
{
$timeout = 0.5;
$process = $this->getProcess('sleep 3');
$process->setTimeout($timeout);
$start = microtime(true);
try {
$process->run();
$this->fail('A RuntimeException should have been raised');
} catch (RuntimeException $e) {
}
$duration = microtime(true) - $start;
$this->assertLessThan($timeout + Process::TIMEOUT_PRECISION, $duration);
}
public function testCheckTimeoutOnStartedProcess()
{
$timeout = 0.5;
$precision = 100000;
$process = $this->getProcess('sleep 3');
$process->setTimeout($timeout);
$start = microtime(true);
$process->start();
try {
while ($process->isRunning()) {
$process->checkTimeout();
usleep($precision);
}
$this->fail('A RuntimeException should have been raised');
} catch (RuntimeException $e) {
}
$duration = microtime(true) - $start;
$this->assertLessThan($timeout + $precision, $duration);
}
public function testGetPid()
{
$process = $this->getProcess('php -r "sleep(1);"');
$process->start();
$this->assertGreaterThan(0, $process->getPid());
$process->stop();
}
public function testGetPidIsNullBeforeStart()
{
$process = $this->getProcess('php -r "sleep(1);"');
$this->assertNull($process->getPid());
}
public function testGetPidIsNullAfterRun()
{
$process = $this->getProcess('php -m');
$process->run();
$this->assertNull($process->getPid());
}
public function testSignal()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('POSIX signals do not work on windows');
}
$process = $this->getProcess('exec php -f ' . __DIR__ . '/SignalListener.php');
$process->start();
usleep(500000);
$process->signal(SIGUSR1);
while ($process->isRunning() && false === strpos($process->getoutput(), 'Caught SIGUSR1')) {
usleep(10000);
}
$this->assertEquals('Caught SIGUSR1', $process->getOutput());
}
/**
* @expectedException Symfony\Component\Process\Exception\LogicException
*/
public function testSignalProcessNotRunning()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('POSIX signals do not work on windows');
}
$process = $this->getProcess('php -m');
$process->signal(SIGHUP);
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongIntSignal()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('POSIX signals do not work on windows');
}
$process = $this->getProcess('php -r "sleep(3);"');
$process->start();
$process->signal(-4);
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongNonIntSignal()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('POSIX signals do not work on windows');
}
$process = $this->getProcess('php -r "sleep(3);"');
$process->start();
$process->signal('Céphalopodes');
}
public function responsesCodeProvider()
{
return array(
//expected output / getter / code to execute
//array(1,'getExitCode','exit(1);'),
//array(true,'isSuccessful','exit();'),
array('output', 'getOutput', 'echo \'output\';'),
);
}
public function pipesCodeProvider()
{
$variations = array(
'fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);',
'include \''.__DIR__.'/ProcessTestHelper.php\';',
);
$codes = array();
foreach (array(1, 16, 64, 1024, 4096) as $size) {
foreach ($variations as $code) {
$codes[] = array($code, $size);
}
}
return $codes;
}
/**
* provides default method names for simple getter/setter
*/
public function methodProvider()
{
$defaults = array(
array('CommandLine'),
array('Timeout'),
array('WorkingDirectory'),
array('Env'),
array('Stdin'),
array('Options')
);
return $defaults;
}
/**
* @param string $commandline
* @param null $cwd
* @param array $env
* @param null $stdin
* @param integer $timeout
* @param array $options
*
* @return Process
*/
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
}
Process-2.3.1/Symfony/Component/Process/Tests/NonStopableProcess.php 0000644 0000765 0000024 00000001452 12155624504 024672 0 ustar fabien staff (microtime(true) - $start)) {
usleep(1000);
}
Process-2.3.1/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php 0000644 0000765 0000024 00000003515 12155624504 025632 0 ustar fabien staff
*
* 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\PhpExecutableFinder;
/**
* @author Robert Schönthal
*/
class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
{
/**
* tests find() with the env var PHP_PATH
*/
public function testFindWithPhpPath()
{
if (defined('PHP_BINARY')) {
$this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
}
$f = new PhpExecutableFinder();
$current = $f->find();
//not executable PHP_PATH
putenv('PHP_PATH=/not/executable/php');
$this->assertFalse($f->find(), '::find() returns false for not executable php');
//executable PHP_PATH
putenv('PHP_PATH='.$current);
$this->assertEquals($f->find(), $current, '::find() returns the executable php');
}
/**
* tests find() with default executable
*/
public function testFindWithSuffix()
{
if (defined('PHP_BINARY')) {
$this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
}
putenv('PHP_PATH=');
putenv('PHP_PEAR_PHP_BIN=');
$f = new PhpExecutableFinder();
$current = $f->find();
//TODO maybe php executable is custom or even windows
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertTrue(is_executable($current));
$this->assertTrue((bool) preg_match('/'.addSlashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable php with suffixes');
}
}
}
Process-2.3.1/Symfony/Component/Process/Tests/PhpProcessTest.php 0000644 0000765 0000024 00000001241 12155624504 024031 0 ustar fabien staff
*
* 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\PhpProcess;
class PhpProcessTest extends \PHPUnit_Framework_TestCase
{
public function testNonBlockingWorks()
{
$expected = 'hello world!';
$process = new PhpProcess(<<start();
$process->wait();
$this->assertEquals($expected, $process->getOutput());
}
}
Process-2.3.1/Symfony/Component/Process/Tests/ProcessBuilderTest.php 0000644 0000765 0000024 00000012546 12155624504 024702 0 ustar fabien staff
*
* 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\ProcessBuilder;
class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testInheritEnvironmentVars()
{
$snapshot = $_ENV;
$_ENV = $expected = array('foo' => 'bar');
$pb = new ProcessBuilder();
$pb->add('foo')->inheritEnvironmentVariables();
$proc = $pb->getProcess();
$this->assertNull($proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
$_ENV = $snapshot;
}
public function testProcessShouldInheritAndOverrideEnvironmentVars()
{
$snapshot = $_ENV;
$_ENV = array('foo' => 'bar', 'bar' => 'baz');
$expected = array('foo' => 'foo', 'bar' => 'baz');
$pb = new ProcessBuilder();
$pb->add('foo')->inheritEnvironmentVariables()
->setEnv('foo', 'foo');
$proc = $pb->getProcess();
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
$_ENV = $snapshot;
}
public function testInheritEnvironmentVarsByDefault()
{
$pb = new ProcessBuilder();
$proc = $pb->add('foo')->getProcess();
$this->assertNull($proc->getEnv());
}
public function testNotReplaceExplicitlySetVars()
{
$snapshot = $_ENV;
$_ENV = array('foo' => 'bar');
$expected = array('foo' => 'baz');
$pb = new ProcessBuilder();
$pb
->setEnv('foo', 'baz')
->inheritEnvironmentVariables()
->add('foo')
;
$proc = $pb->getProcess();
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
$_ENV = $snapshot;
}
/**
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromSetter()
{
$pb = new ProcessBuilder();
$pb->setTimeout(-1);
}
public function testNullTimeout()
{
$pb = new ProcessBuilder();
$pb->setTimeout(10);
$pb->setTimeout(null);
$r = new \ReflectionObject($pb);
$p = $r->getProperty('timeout');
$p->setAccessible(true);
$this->assertNull($p->getValue($pb));
}
public function testShouldSetArguments()
{
$pb = new ProcessBuilder(array('initial'));
$pb->setArguments(array('second'));
$proc = $pb->getProcess();
$this->assertContains("second", $proc->getCommandLine());
}
public function testPrefixIsPrependedToAllGeneratedProcess()
{
$pb = new ProcessBuilder();
$pb->setPrefix('/usr/bin/php');
$proc = $pb->setArguments(array('-v'))->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertEquals('"/usr/bin/php" "-v"', $proc->getCommandLine());
} else {
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
}
$proc = $pb->setArguments(array('-i'))->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertEquals('"/usr/bin/php" "-i"', $proc->getCommandLine());
} else {
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
}
}
public function testShouldEscapeArguments()
{
$pb = new ProcessBuilder(array('%path%', 'foo " bar'));
$proc = $pb->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertSame('^%"path"^% "foo "\\"" bar"', $proc->getCommandLine());
} else {
$this->assertSame("'%path%' 'foo \" bar'", $proc->getCommandLine());
}
}
public function testShouldEscapeArgumentsAndPrefix()
{
$pb = new ProcessBuilder(array('arg'));
$pb->setPrefix('%prefix%');
$proc = $pb->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertSame('^%"prefix"^% "arg"', $proc->getCommandLine());
} else {
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
}
}
/**
* @expectedException \Symfony\Component\Process\Exception\LogicException
*/
public function testShouldThrowALogicExceptionIfNoPrefixAndNoArgument()
{
ProcessBuilder::create()->getProcess();
}
public function testShouldNotThrowALogicExceptionIfNoArgument()
{
$process = ProcessBuilder::create()
->setPrefix('/usr/bin/php')
->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
} else {
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
}
}
public function testShouldNotThrowALogicExceptionIfNoPrefix()
{
$process = ProcessBuilder::create(array('/usr/bin/php'))
->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
} else {
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
}
}
}
Process-2.3.1/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php 0000644 0000765 0000024 00000005223 12155624504 026351 0 ustar fabien staff
*
* 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\Exception\ProcessFailedException;
/**
* @author Sebastian Marek
*/
class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* tests ProcessFailedException throws exception if the process was successful
*/
public function testProcessFailedExceptionThrowsException()
{
$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful'),
array('php')
);
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(true));
$this->setExpectedException(
'\InvalidArgumentException',
'Expected a failed process, but the given process was successful.'
);
new ProcessFailedException($process);
}
/**
* tests ProcessFailedException uses information from process output
* to generate exception message
*/
public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
{
$cmd = 'php';
$exitCode = 1;
$exitText = 'General error';
$output = "Command output";
$errorOutput = "FATAL: Unexpected error";
$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText'),
array($cmd)
);
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));
$process->expects($this->once())
->method('getOutput')
->will($this->returnValue($output));
$process->expects($this->once())
->method('getErrorOutput')
->will($this->returnValue($errorOutput));
$process->expects($this->once())
->method('getExitCode')
->will($this->returnValue($exitCode));
$process->expects($this->once())
->method('getExitCodeText')
->will($this->returnValue($exitText));
$exception = new ProcessFailedException($process);
$this->assertEquals(
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
$exception->getMessage()
);
}
}
Process-2.3.1/Symfony/Component/Process/Tests/ProcessInSigchildEnvironment.php 0000644 0000765 0000024 00000000705 12155624504 026710 0 ustar fabien staff
*
* 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;
}
}
Process-2.3.1/Symfony/Component/Process/Tests/ProcessTestHelper.php 0000644 0000765 0000024 00000003017 12155624504 024524 0 ustar fabien staff 0) {
$written = fwrite(STDOUT, (binary) $out, 1024);
if (false === $written) {
die(ERR_WRITE_FAILED);
}
$out = (binary) substr($out, $written);
}
if (null === $read && strlen($out) < 1) {
$write = array_diff($write, array(STDOUT));
}
if (in_array(STDERR, $w) && strlen($err) > 0) {
$written = fwrite(STDERR, (binary) $err, 1024);
if (false === $written) {
die(ERR_WRITE_FAILED);
}
$err = (binary) substr($err, $written);
}
if (null === $read && strlen($err) < 1) {
$write = array_diff($write, array(STDERR));
}
if ($r) {
$str = fread(STDIN, 1024);
if (false !== $str) {
$out .= $str;
$err .= $str;
}
if (false === $str || feof(STDIN)) {
$read = null;
if (!feof(STDIN)) {
die(ERR_READ_FAILED);
}
}
}
}
Process-2.3.1/Symfony/Component/Process/Tests/ProcessUtilsTest.php 0000644 0000765 0000024 00000002050 12155624504 024401 0 ustar fabien staff
*
* 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\ProcessUtils;
class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataArguments
*/
public function testEscapeArgument($result, $argument)
{
$this->assertSame($result, ProcessUtils::escapeArgument($argument));
}
public function dataArguments()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return array(
array('"foo bar"', 'foo bar'),
array('^%"path"^%', '%path%'),
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
);
}
return array(
array("'foo bar'", 'foo bar'),
array("'%path%'", '%path%'),
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
);
}
}
Process-2.3.1/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php 0000644 0000765 0000024 00000007470 12155624504 026472 0 ustar fabien staff
*
* 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
*/
public function testGetExitCode()
{
parent::testGetExitCode();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testExitCodeCommandFailed()
{
parent::testExitCodeCommandFailed();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessIsSignaledIfStopped()
{
parent::testProcessIsSignaledIfStopped();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessWithTermSignal()
{
parent::testProcessWithTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessIsNotSignaled()
{
parent::testProcessIsNotSignaled();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessWithoutTermSignal()
{
parent::testProcessWithoutTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testGetPid()
{
parent::testGetPid();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testGetPidIsNullBeforeStart()
{
parent::testGetPidIsNullBeforeStart();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testGetPidIsNullAfterRun()
{
parent::testGetPidIsNullAfterRun();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testExitCodeText()
{
$process = $this->getProcess('qdfsmfkqsdfmqmsd');
$process->run();
$process->getExitCodeText();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testIsSuccessful()
{
parent::testIsSuccessful();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testIsNotSuccessful()
{
parent::testIsNotSuccessful();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignal()
{
parent::testSignal();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
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');
}
/**
* {@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;
}
}
Process-2.3.1/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php 0000644 0000765 0000024 00000005534 12155624504 026314 0 ustar fabien staff
*
* 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
*/
public function testProcessIsSignaledIfStopped()
{
parent::testProcessIsSignaledIfStopped();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessWithTermSignal()
{
parent::testProcessWithTermSignal();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessIsNotSignaled()
{
parent::testProcessIsNotSignaled();
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessWithoutTermSignal()
{
parent::testProcessWithoutTermSignal();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testGetPid()
{
parent::testGetPid();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testGetPidIsNullBeforeStart()
{
parent::testGetPidIsNullBeforeStart();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
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
*/
public function testSignal()
{
parent::testSignal();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testProcessWithoutTermSignalIsNotSignaled()
{
parent::testProcessWithoutTermSignalIsNotSignaled();
}
public function testProcessThrowsExceptionWhenExternallySignaled()
{
$this->markTestSkipped('Retrieving Pid 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;
}
}
Process-2.3.1/Symfony/Component/Process/Tests/SignalListener.php 0000644 0000765 0000024 00000000372 12155624504 024032 0 ustar fabien staff
*
* 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;
public function setUp()
{
ob_start();
phpinfo(INFO_GENERAL);
$this->enabledSigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
}
public function testGetExitCode()
{
$this->skipIfPHPSigchild();
parent::testGetExitCode();
}
public function testExitCodeCommandFailed()
{
$this->skipIfPHPSigchild();
parent::testExitCodeCommandFailed();
}
public function testProcessIsSignaledIfStopped()
{
$this->skipIfPHPSigchild();
parent::testProcessIsSignaledIfStopped();
}
public function testProcessWithTermSignal()
{
$this->skipIfPHPSigchild();
parent::testProcessWithTermSignal();
}
public function testProcessIsNotSignaled()
{
$this->skipIfPHPSigchild();
parent::testProcessIsNotSignaled();
}
public function testProcessWithoutTermSignal()
{
$this->skipIfPHPSigchild();
parent::testProcessWithoutTermSignal();
}
public function testExitCodeText()
{
$this->skipIfPHPSigchild();
parent::testExitCodeText();
}
public function testIsSuccessful()
{
$this->skipIfPHPSigchild();
parent::testIsSuccessful();
}
public function testIsNotSuccessful()
{
$this->skipIfPHPSigchild();
parent::testIsNotSuccessful();
}
public function testGetPid()
{
$this->skipIfPHPSigchild();
parent::testGetPid();
}
public function testGetPidIsNullBeforeStart()
{
$this->skipIfPHPSigchild();
parent::testGetPidIsNullBeforeStart();
}
public function testGetPidIsNullAfterRun()
{
$this->skipIfPHPSigchild();
parent::testGetPidIsNullAfterRun();
}
public function testSignal()
{
$this->skipIfPHPSigchild();
parent::testSignal();
}
/**
* @expectedException Symfony\Component\Process\Exception\LogicException
*/
public function testSignalProcessNotRunning()
{
$this->skipIfPHPSigchild();
parent::testSignalProcessNotRunning();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongIntSignal()
{
$this->skipIfPHPSigchild();
parent::testSignalWithWrongIntSignal();
}
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongNonIntSignal()
{
$this->skipIfPHPSigchild();
parent::testSignalWithWrongNonIntSignal();
}
/**
* {@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');
}
}
}