Add pear modules, mail and net_smtp via composer (#93)
Add pear modules, mail and net_smtp via composer, remove php 5.6 build due to phpunit 6
This commit is contained in:
17
lib/composer/vendor/symfony/process/CHANGELOG.md
vendored
17
lib/composer/vendor/symfony/process/CHANGELOG.md
vendored
@@ -1,6 +1,23 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* deprecated the ProcessBuilder class
|
||||
* deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor)
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* added command line arrays in the `Process` class
|
||||
* added `$env` argument to `Process::start()`, `run()`, `mustRun()` and `restart()` methods
|
||||
* deprecated the `ProcessUtils::escapeArgument()` method
|
||||
* deprecated not inheriting environment variables
|
||||
* deprecated configuring `proc_open()` options
|
||||
* deprecated configuring enhanced Windows compatibility
|
||||
* deprecated configuring enhanced sigchild compatibility
|
||||
|
||||
2.5.0
|
||||
-----
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ class ProcessTimedOutException extends RuntimeException
|
||||
|
||||
public function isGeneralTimeout()
|
||||
{
|
||||
return $this->timeoutType === self::TYPE_GENERAL;
|
||||
return self::TYPE_GENERAL === $this->timeoutType;
|
||||
}
|
||||
|
||||
public function isIdleTimeout()
|
||||
{
|
||||
return $this->timeoutType === self::TYPE_IDLE;
|
||||
return self::TYPE_IDLE === $this->timeoutType;
|
||||
}
|
||||
|
||||
public function getExceededTimeout()
|
||||
|
||||
@@ -23,8 +23,6 @@ class ExecutableFinder
|
||||
|
||||
/**
|
||||
* Replaces default suffixes of executable.
|
||||
*
|
||||
* @param array $suffixes
|
||||
*/
|
||||
public function setSuffixes(array $suffixes)
|
||||
{
|
||||
@@ -75,7 +73,7 @@ class ExecutableFinder
|
||||
$suffixes = array('');
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$pathExt = getenv('PATHEXT');
|
||||
$suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
|
||||
$suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
|
||||
}
|
||||
foreach ($suffixes as $suffix) {
|
||||
foreach ($dirs as $dir) {
|
||||
|
||||
2
lib/composer/vendor/symfony/process/LICENSE
vendored
2
lib/composer/vendor/symfony/process/LICENSE
vendored
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2016 Fabien Potencier
|
||||
Copyright (c) 2004-2018 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
|
||||
|
||||
@@ -25,32 +25,29 @@ use Symfony\Component\Process\Exception\RuntimeException;
|
||||
class PhpProcess extends Process
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $script The PHP script to run (as a string)
|
||||
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
|
||||
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
|
||||
* @param int $timeout The timeout in seconds
|
||||
* @param array $options An array of options for proc_open
|
||||
*/
|
||||
public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = array())
|
||||
public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = null)
|
||||
{
|
||||
$executableFinder = new PhpExecutableFinder();
|
||||
if (false === $php = $executableFinder->find()) {
|
||||
if (false === $php = $executableFinder->find(false)) {
|
||||
$php = null;
|
||||
} else {
|
||||
$php = array_merge(array($php), $executableFinder->findArguments());
|
||||
}
|
||||
if ('phpdbg' === PHP_SAPI) {
|
||||
$file = tempnam(sys_get_temp_dir(), 'dbg');
|
||||
file_put_contents($file, $script);
|
||||
register_shutdown_function('unlink', $file);
|
||||
$php .= ' '.ProcessUtils::escapeArgument($file);
|
||||
$php[] = $file;
|
||||
$script = null;
|
||||
}
|
||||
if ('\\' !== DIRECTORY_SEPARATOR && null !== $php) {
|
||||
// exec is mandatory to deal with sending a signal to the process
|
||||
// see https://github.com/symfony/symfony/issues/5030 about prepending
|
||||
// command with exec
|
||||
$php = 'exec '.$php;
|
||||
if (null !== $options) {
|
||||
@trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
|
||||
@@ -67,12 +64,13 @@ class PhpProcess extends Process
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function start(callable $callback = null)
|
||||
public function start(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if (null === $this->getCommandLine()) {
|
||||
throw new RuntimeException('Unable to find the PHP executable.');
|
||||
}
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
parent::start($callback);
|
||||
parent::start($callback, $env);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,16 +20,15 @@ use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
*/
|
||||
abstract class AbstractPipes implements PipesInterface
|
||||
{
|
||||
/** @var array */
|
||||
public $pipes = array();
|
||||
|
||||
/** @var string */
|
||||
private $inputBuffer = '';
|
||||
/** @var resource|scalar|\Iterator|null */
|
||||
private $input;
|
||||
/** @var bool */
|
||||
private $blocked = true;
|
||||
|
||||
/**
|
||||
* @param resource|scalar|\Iterator|null $input
|
||||
*/
|
||||
public function __construct($input)
|
||||
{
|
||||
if (is_resource($input) || $input instanceof \Iterator) {
|
||||
@@ -120,7 +119,7 @@ abstract class AbstractPipes implements PipesInterface
|
||||
$w = array($this->pipes[0]);
|
||||
|
||||
// let's have a look if something changed in streams
|
||||
if (false === $n = @stream_select($r, $w, $e, 0, 0)) {
|
||||
if (false === @stream_select($r, $w, $e, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,8 @@ use Symfony\Component\Process\Process;
|
||||
*/
|
||||
class UnixPipes extends AbstractPipes
|
||||
{
|
||||
/** @var bool */
|
||||
private $ttyMode;
|
||||
/** @var bool */
|
||||
private $ptyMode;
|
||||
/** @var bool */
|
||||
private $haveReadSupport;
|
||||
|
||||
public function __construct($ttyMode, $ptyMode, $input, $haveReadSupport)
|
||||
@@ -102,7 +99,7 @@ class UnixPipes extends AbstractPipes
|
||||
unset($r[0]);
|
||||
|
||||
// let's have a look if something changed in streams
|
||||
if (($r || $w) && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
|
||||
if (($r || $w) && false === @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
|
||||
// if a system call has been interrupted, forget about it, let's try again
|
||||
// otherwise, an error occurred, let's reset pipes
|
||||
if (!$this->hasSystemCallBeenInterrupted()) {
|
||||
|
||||
@@ -26,16 +26,12 @@ use Symfony\Component\Process\Exception\RuntimeException;
|
||||
*/
|
||||
class WindowsPipes extends AbstractPipes
|
||||
{
|
||||
/** @var array */
|
||||
private $files = array();
|
||||
/** @var array */
|
||||
private $fileHandles = array();
|
||||
/** @var array */
|
||||
private $readBytes = array(
|
||||
Process::STDOUT => 0,
|
||||
Process::STDERR => 0,
|
||||
);
|
||||
/** @var bool */
|
||||
private $haveReadSupport;
|
||||
|
||||
public function __construct($input, $haveReadSupport)
|
||||
|
||||
307
lib/composer/vendor/symfony/process/Process.php
vendored
307
lib/composer/vendor/symfony/process/Process.php
vendored
@@ -58,7 +58,7 @@ class Process implements \IteratorAggregate
|
||||
private $lastOutputTime;
|
||||
private $timeout;
|
||||
private $idleTimeout;
|
||||
private $options;
|
||||
private $options = array('suppress_errors' => true);
|
||||
private $exitcode;
|
||||
private $fallbackStatus = array();
|
||||
private $processInformation;
|
||||
@@ -73,6 +73,7 @@ class Process implements \IteratorAggregate
|
||||
private $incrementalErrorOutputOffset = 0;
|
||||
private $tty;
|
||||
private $pty;
|
||||
private $inheritEnv = false;
|
||||
|
||||
private $useFileHandles = false;
|
||||
/** @var PipesInterface */
|
||||
@@ -86,8 +87,6 @@ class Process implements \IteratorAggregate
|
||||
* Exit codes translation table.
|
||||
*
|
||||
* User-defined errors must use exit codes in the 64-113 range.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $exitCodes = array(
|
||||
0 => 'OK',
|
||||
@@ -133,9 +132,7 @@ class Process implements \IteratorAggregate
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $commandline The command line to run
|
||||
* @param string|array $commandline The command line to run
|
||||
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
|
||||
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
|
||||
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
|
||||
@@ -144,7 +141,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws RuntimeException When proc_open is not installed
|
||||
*/
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null)
|
||||
{
|
||||
if (!function_exists('proc_open')) {
|
||||
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
|
||||
@@ -168,9 +165,11 @@ class Process implements \IteratorAggregate
|
||||
$this->setTimeout($timeout);
|
||||
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
|
||||
$this->pty = false;
|
||||
$this->enhanceWindowsCompatibility = true;
|
||||
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
|
||||
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
|
||||
if (null !== $options) {
|
||||
@trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
|
||||
$this->options = array_replace($this->options, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
@@ -195,16 +194,20 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return int The exit status code
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process stopped after receiving signal
|
||||
* @throws LogicException In case a callback is provided and output has been disabled
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function run($callback = null)
|
||||
public function run($callback = null/*, array $env = array()*/)
|
||||
{
|
||||
$this->start($callback);
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
$this->start($callback, $env);
|
||||
|
||||
return $this->wait();
|
||||
}
|
||||
@@ -216,19 +219,23 @@ class Process implements \IteratorAggregate
|
||||
* exits with a non-zero exit code.
|
||||
*
|
||||
* @param callable|null $callback
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
|
||||
* @throws ProcessFailedException if the process didn't terminate successfully
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function mustRun(callable $callback = null)
|
||||
public function mustRun(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
||||
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
|
||||
}
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
if (0 !== $this->run($callback)) {
|
||||
if (0 !== $this->run($callback, $env)) {
|
||||
throw new ProcessFailedException($this);
|
||||
}
|
||||
|
||||
@@ -249,49 +256,90 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process is already running
|
||||
* @throws LogicException In case a callback is provided and output has been disabled
|
||||
*/
|
||||
public function start(callable $callback = null)
|
||||
public function start(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Process is already running');
|
||||
}
|
||||
if (2 <= func_num_args()) {
|
||||
$env = func_get_arg(1);
|
||||
} else {
|
||||
if (__CLASS__ !== static::class) {
|
||||
$r = new \ReflectionMethod($this, __FUNCTION__);
|
||||
if (__CLASS__ !== $r->getDeclaringClass()->getName() && (2 > $r->getNumberOfParameters() || 'env' !== $r->getParameters()[0]->name)) {
|
||||
@trigger_error(sprintf('The %s::start() method expects a second "$env" argument since Symfony 3.3. It will be made mandatory in 4.0.', static::class), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
$env = null;
|
||||
}
|
||||
|
||||
$this->resetProcessData();
|
||||
$this->starttime = $this->lastOutputTime = microtime(true);
|
||||
$this->callback = $this->buildCallback($callback);
|
||||
$this->hasCallback = null !== $callback;
|
||||
$descriptors = $this->getDescriptors();
|
||||
$inheritEnv = $this->inheritEnv;
|
||||
|
||||
$commandline = $this->commandline;
|
||||
if (is_array($commandline = $this->commandline)) {
|
||||
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
|
||||
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
// exec is mandatory to deal with sending a signal to the process
|
||||
$commandline = 'exec '.$commandline;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $env) {
|
||||
$env = $this->env;
|
||||
} else {
|
||||
if ($this->env) {
|
||||
$env += $this->env;
|
||||
}
|
||||
$inheritEnv = true;
|
||||
}
|
||||
|
||||
if (null !== $env && $inheritEnv) {
|
||||
$env += $this->getDefaultEnv();
|
||||
} elseif (null !== $env) {
|
||||
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
|
||||
} else {
|
||||
$env = $this->getDefaultEnv();
|
||||
}
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
|
||||
$commandline = 'cmd /V:ON /E:ON /D /C "('.$commandline.')';
|
||||
foreach ($this->processPipes->getFiles() as $offset => $filename) {
|
||||
$commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
|
||||
}
|
||||
$commandline .= '"';
|
||||
|
||||
if (!isset($this->options['bypass_shell'])) {
|
||||
$this->options['bypass_shell'] = true;
|
||||
}
|
||||
$this->options['bypass_shell'] = true;
|
||||
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
|
||||
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
||||
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
|
||||
$descriptors[3] = array('pipe', 'w');
|
||||
|
||||
// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
|
||||
$commandline = '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
|
||||
$commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
|
||||
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';
|
||||
|
||||
// Workaround for the bug, when PTS functionality is enabled.
|
||||
// @see : https://bugs.php.net/69442
|
||||
$ptsWorkaround = fopen(__FILE__, 'r');
|
||||
}
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$envPairs = $env;
|
||||
} else {
|
||||
$envPairs = array();
|
||||
foreach ($env as $k => $v) {
|
||||
$envPairs[] = $k.'='.$v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
|
||||
if (!is_dir($this->cwd)) {
|
||||
@trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
|
||||
|
||||
if (!is_resource($this->process)) {
|
||||
throw new RuntimeException('Unable to launch a new process.');
|
||||
@@ -317,22 +365,26 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return Process The new process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process is already running
|
||||
*
|
||||
* @see start()
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function restart(callable $callback = null)
|
||||
public function restart(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Process is already running');
|
||||
}
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
$process = clone $this;
|
||||
$process->start($callback);
|
||||
$process->start($callback, $env);
|
||||
|
||||
return $process;
|
||||
}
|
||||
@@ -361,7 +413,7 @@ class Process implements \IteratorAggregate
|
||||
if (null !== $callback) {
|
||||
if (!$this->processPipes->haveReadSupport()) {
|
||||
$this->stop(0);
|
||||
throw new \LogicException('Pass the callback to the Process:start method or enableOutput to use a callback with Process::wait');
|
||||
throw new \LogicException('Pass the callback to the Process::start method or enableOutput to use a callback with Process::wait');
|
||||
}
|
||||
$this->callback = $this->buildCallback($callback);
|
||||
}
|
||||
@@ -398,7 +450,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param int $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException In case the process is not running
|
||||
* @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
|
||||
@@ -414,7 +466,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Disables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException In case the process is already running
|
||||
* @throws LogicException if an idle timeout is set
|
||||
@@ -436,7 +488,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Enables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException In case the process is already running
|
||||
*/
|
||||
@@ -557,6 +609,7 @@ class Process implements \IteratorAggregate
|
||||
yield self::OUT => '';
|
||||
}
|
||||
|
||||
$this->checkTimeout();
|
||||
$this->readPipesForOutput(__FUNCTION__, $blocking);
|
||||
}
|
||||
}
|
||||
@@ -564,7 +617,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Clears the process output.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*/
|
||||
public function clearOutput()
|
||||
{
|
||||
@@ -623,7 +676,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Clears the process output.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*/
|
||||
public function clearErrorOutput()
|
||||
{
|
||||
@@ -779,7 +832,7 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->status != self::STATUS_READY;
|
||||
return self::STATUS_READY != $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -791,7 +844,7 @@ class Process implements \IteratorAggregate
|
||||
{
|
||||
$this->updateStatus(false);
|
||||
|
||||
return $this->status == self::STATUS_TERMINATED;
|
||||
return self::STATUS_TERMINATED == $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -884,13 +937,13 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function getCommandLine()
|
||||
{
|
||||
return $this->commandline;
|
||||
return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command line to be executed.
|
||||
*
|
||||
* @param string $commandline The command to execute
|
||||
* @param string|array $commandline The command to execute
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*/
|
||||
@@ -976,8 +1029,16 @@ class Process implements \IteratorAggregate
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
|
||||
throw new RuntimeException('TTY mode is not supported on Windows platform.');
|
||||
}
|
||||
if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
|
||||
throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
|
||||
if ($tty) {
|
||||
static $isTtySupported;
|
||||
|
||||
if (null === $isTtySupported) {
|
||||
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
|
||||
}
|
||||
|
||||
if (!$isTtySupported) {
|
||||
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->tty = (bool) $tty;
|
||||
@@ -1064,6 +1125,8 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* An environment variable value should be a string.
|
||||
* If it is an array, the variable is ignored.
|
||||
* If it is false or null, it will be removed when
|
||||
* env vars are otherwise inherited.
|
||||
*
|
||||
* That happens in PHP when 'argv' is registered into
|
||||
* the $_ENV array for instance.
|
||||
@@ -1079,10 +1142,7 @@ class Process implements \IteratorAggregate
|
||||
return !is_array($value);
|
||||
});
|
||||
|
||||
$this->env = array();
|
||||
foreach ($env as $key => $value) {
|
||||
$this->env[$key] = (string) $value;
|
||||
}
|
||||
$this->env = $env;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1123,9 +1183,13 @@ class Process implements \IteratorAggregate
|
||||
* Gets the options for proc_open.
|
||||
*
|
||||
* @return array The current options
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
@@ -1135,9 +1199,13 @@ class Process implements \IteratorAggregate
|
||||
* @param array $options The new options
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
@@ -1149,9 +1217,13 @@ class Process implements \IteratorAggregate
|
||||
* This is true by default.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
|
||||
*/
|
||||
public function getEnhanceWindowsCompatibility()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->enhanceWindowsCompatibility;
|
||||
}
|
||||
|
||||
@@ -1161,9 +1233,13 @@ class Process implements \IteratorAggregate
|
||||
* @param bool $enhance
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
|
||||
*/
|
||||
public function setEnhanceWindowsCompatibility($enhance)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->enhanceWindowsCompatibility = (bool) $enhance;
|
||||
|
||||
return $this;
|
||||
@@ -1173,9 +1249,13 @@ class Process implements \IteratorAggregate
|
||||
* Returns whether sigchild compatibility mode is activated or not.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Sigchild compatibility will always be enabled.
|
||||
*/
|
||||
public function getEnhanceSigchildCompatibility()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->enhanceSigchildCompatibility;
|
||||
}
|
||||
|
||||
@@ -1189,14 +1269,50 @@ class Process implements \IteratorAggregate
|
||||
* @param bool $enhance
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setEnhanceSigchildCompatibility($enhance)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->enhanceSigchildCompatibility = (bool) $enhance;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether environment variables will be inherited or not.
|
||||
*
|
||||
* @param bool $inheritEnv
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*/
|
||||
public function inheritEnvironmentVariables($inheritEnv = true)
|
||||
{
|
||||
if (!$inheritEnv) {
|
||||
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->inheritEnv = (bool) $inheritEnv;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether environment variables will be inherited or not.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Environment variables will always be inherited.
|
||||
*/
|
||||
public function areEnvironmentVariablesInherited()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Environment variables will always be inherited.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->inheritEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a check between the timeout definition and the time the process started.
|
||||
*
|
||||
@@ -1207,7 +1323,7 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function checkTimeout()
|
||||
{
|
||||
if ($this->status !== self::STATUS_STARTED) {
|
||||
if (self::STATUS_STARTED !== $this->status) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1241,7 +1357,7 @@ class Process implements \IteratorAggregate
|
||||
return $result = false;
|
||||
}
|
||||
|
||||
return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
|
||||
return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1398,7 +1514,7 @@ class Process implements \IteratorAggregate
|
||||
$callback = $this->callback;
|
||||
foreach ($result as $type => $data) {
|
||||
if (3 !== $type) {
|
||||
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
|
||||
$callback(self::STDOUT === $type ? self::OUT : self::ERR, $data);
|
||||
} elseif (!isset($this->fallbackStatus['signaled'])) {
|
||||
$this->fallbackStatus['exitcode'] = (int) $data;
|
||||
}
|
||||
@@ -1512,12 +1628,58 @@ class Process implements \IteratorAggregate
|
||||
return true;
|
||||
}
|
||||
|
||||
private function prepareWindowsCommandLine($cmd, array &$env)
|
||||
{
|
||||
$uid = uniqid('', true);
|
||||
$varCount = 0;
|
||||
$varCache = array();
|
||||
$cmd = preg_replace_callback(
|
||||
'/"(?:(
|
||||
[^"%!^]*+
|
||||
(?:
|
||||
(?: !LF! | "(?:\^[%!^])?+" )
|
||||
[^"%!^]*+
|
||||
)++
|
||||
) | [^"]*+ )"/x',
|
||||
function ($m) use (&$env, &$varCache, &$varCount, $uid) {
|
||||
if (!isset($m[1])) {
|
||||
return $m[0];
|
||||
}
|
||||
if (isset($varCache[$m[0]])) {
|
||||
return $varCache[$m[0]];
|
||||
}
|
||||
if (false !== strpos($value = $m[1], "\0")) {
|
||||
$value = str_replace("\0", '?', $value);
|
||||
}
|
||||
if (false === strpbrk($value, "\"%!\n")) {
|
||||
return '"'.$value.'"';
|
||||
}
|
||||
|
||||
$value = str_replace(array('!LF!', '"^!"', '"^%"', '"^^"', '""'), array("\n", '!', '%', '^', '"'), $value);
|
||||
$value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"';
|
||||
$var = $uid.++$varCount;
|
||||
|
||||
$env[$var] = $value;
|
||||
|
||||
return $varCache[$m[0]] = '!'.$var.'!';
|
||||
},
|
||||
$cmd
|
||||
);
|
||||
|
||||
$cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')';
|
||||
foreach ($this->processPipes->getFiles() as $offset => $filename) {
|
||||
$cmd .= ' '.$offset.'>"'.$filename.'"';
|
||||
}
|
||||
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the process is running or terminated, throws a LogicException if the process has a not started.
|
||||
*
|
||||
* @param string $functionName The function name that was called
|
||||
*
|
||||
* @throws LogicException If the process has not run.
|
||||
* @throws LogicException if the process has not run
|
||||
*/
|
||||
private function requireProcessIsStarted($functionName)
|
||||
{
|
||||
@@ -1531,7 +1693,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param string $functionName The function name that was called
|
||||
*
|
||||
* @throws LogicException If the process is not yet terminated.
|
||||
* @throws LogicException if the process is not yet terminated
|
||||
*/
|
||||
private function requireProcessIsTerminated($functionName)
|
||||
{
|
||||
@@ -1539,4 +1701,49 @@ class Process implements \IteratorAggregate
|
||||
throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string to be used as a shell argument.
|
||||
*
|
||||
* @param string $argument The argument that will be escaped
|
||||
*
|
||||
* @return string The escaped argument
|
||||
*/
|
||||
private function escapeArgument($argument)
|
||||
{
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
return "'".str_replace("'", "'\\''", $argument)."'";
|
||||
}
|
||||
if ('' === $argument = (string) $argument) {
|
||||
return '""';
|
||||
}
|
||||
if (false !== strpos($argument, "\0")) {
|
||||
$argument = str_replace("\0", '?', $argument);
|
||||
}
|
||||
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
|
||||
return $argument;
|
||||
}
|
||||
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
|
||||
|
||||
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
|
||||
}
|
||||
|
||||
private function getDefaultEnv()
|
||||
{
|
||||
$env = array();
|
||||
|
||||
foreach ($_SERVER as $k => $v) {
|
||||
if (is_string($v) && false !== $v = getenv($k)) {
|
||||
$env[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_ENV as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$env[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,15 @@
|
||||
|
||||
namespace Symfony\Component\Process;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the Process class instead.', ProcessBuilder::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Process\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* Process builder.
|
||||
*
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use the Process class instead.
|
||||
*/
|
||||
class ProcessBuilder
|
||||
{
|
||||
@@ -26,14 +28,12 @@ class ProcessBuilder
|
||||
private $env = array();
|
||||
private $input;
|
||||
private $timeout = 60;
|
||||
private $options = array();
|
||||
private $options;
|
||||
private $inheritEnv = true;
|
||||
private $prefix = array();
|
||||
private $outputDisabled = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string[] $arguments An array of arguments
|
||||
*/
|
||||
public function __construct(array $arguments = array())
|
||||
@@ -46,7 +46,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param string[] $arguments An array of arguments
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return static
|
||||
*/
|
||||
public static function create(array $arguments = array())
|
||||
{
|
||||
@@ -58,7 +58,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param string $argument A command argument
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function add($argument)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param string|array $prefix A command prefix or an array of command prefixes
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param string[] $arguments
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param null|string $cwd The working directory
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setWorkingDirectory($cwd)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param bool $inheritEnv
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function inheritEnvironmentVariables($inheritEnv = true)
|
||||
{
|
||||
@@ -137,7 +137,7 @@ class ProcessBuilder
|
||||
* @param string $name The variable name
|
||||
* @param null|string $value The variable value
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setEnv($name, $value)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param array $variables The variables
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function addEnvironmentVariables(array $variables)
|
||||
{
|
||||
@@ -169,7 +169,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param resource|scalar|\Traversable|null $input The input content
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException In case the argument is invalid
|
||||
*/
|
||||
@@ -187,7 +187,7 @@ class ProcessBuilder
|
||||
*
|
||||
* @param float|null $timeout
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -216,7 +216,7 @@ class ProcessBuilder
|
||||
* @param string $name The option name
|
||||
* @param string $value The option value
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
@@ -228,7 +228,7 @@ class ProcessBuilder
|
||||
/**
|
||||
* Disables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function disableOutput()
|
||||
{
|
||||
@@ -240,7 +240,7 @@ class ProcessBuilder
|
||||
/**
|
||||
* Enables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function enableOutput()
|
||||
{
|
||||
@@ -262,19 +262,15 @@ class ProcessBuilder
|
||||
throw new LogicException('You must add() command arguments before calling getProcess().');
|
||||
}
|
||||
|
||||
$options = $this->options;
|
||||
|
||||
$arguments = array_merge($this->prefix, $this->arguments);
|
||||
$script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
|
||||
$process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options);
|
||||
// to preserve the BC with symfony <3.3, we convert the array structure
|
||||
// to a string structure to avoid the prefixing with the exec command
|
||||
$process->setCommandLine($process->getCommandLine());
|
||||
|
||||
if ($this->inheritEnv) {
|
||||
$env = array_replace($_ENV, $_SERVER, $this->env);
|
||||
} else {
|
||||
$env = $this->env;
|
||||
$process->inheritEnvironmentVariables();
|
||||
}
|
||||
|
||||
$process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
|
||||
|
||||
if ($this->outputDisabled) {
|
||||
$process->disableOutput();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,13 @@ class ProcessUtils
|
||||
* @param string $argument The argument that will be escaped
|
||||
*
|
||||
* @return string The escaped argument
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.
|
||||
*/
|
||||
public static function escapeArgument($argument)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use a command line array or give env vars to the Process::start/run() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
//Fix for PHP bug #43784 escapeshellarg removes % from given string
|
||||
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
|
||||
//@see https://bugs.php.net/bug.php?id=43784
|
||||
@@ -71,7 +75,7 @@ class ProcessUtils
|
||||
return $escapedArgument;
|
||||
}
|
||||
|
||||
return escapeshellarg($argument);
|
||||
return "'".str_replace("'", "'\\''", $argument)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
/**
|
||||
* @author Chris Smith <chris@cs278.org>
|
||||
*/
|
||||
class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
||||
class ExecutableFinderTest extends TestCase
|
||||
{
|
||||
private $path;
|
||||
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
/**
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
*/
|
||||
class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
||||
class PhpExecutableFinderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* tests find() with the constant PHP_BINARY.
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\PhpProcess;
|
||||
|
||||
class PhpProcessTest extends \PHPUnit_Framework_TestCase
|
||||
class PhpProcessTest extends TestCase
|
||||
{
|
||||
public function testNonBlockingWorks()
|
||||
{
|
||||
@@ -31,19 +31,18 @@ PHP
|
||||
public function testCommandLine()
|
||||
{
|
||||
$process = new PhpProcess(<<<'PHP'
|
||||
<?php echo 'foobar';
|
||||
<?php echo phpversion().PHP_SAPI;
|
||||
PHP
|
||||
);
|
||||
|
||||
$commandLine = $process->getCommandLine();
|
||||
|
||||
$f = new PhpExecutableFinder();
|
||||
$this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start');
|
||||
|
||||
$process->start();
|
||||
$this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
|
||||
|
||||
$process->wait();
|
||||
$this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
|
||||
|
||||
$this->assertSame(PHP_VERSION.PHP_SAPI, $process->getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,23 +11,28 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\ProcessBuilder;
|
||||
|
||||
class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ProcessBuilderTest extends TestCase
|
||||
{
|
||||
public function testInheritEnvironmentVars()
|
||||
{
|
||||
$_ENV['MY_VAR_1'] = 'foo';
|
||||
|
||||
$proc = ProcessBuilder::create()
|
||||
->add('foo')
|
||||
->getProcess();
|
||||
|
||||
unset($_ENV['MY_VAR_1']);
|
||||
$this->assertTrue($proc->areEnvironmentVariablesInherited());
|
||||
|
||||
$env = $proc->getEnv();
|
||||
$this->assertArrayHasKey('MY_VAR_1', $env);
|
||||
$this->assertEquals('foo', $env['MY_VAR_1']);
|
||||
$proc = ProcessBuilder::create()
|
||||
->add('foo')
|
||||
->inheritEnvironmentVariables(false)
|
||||
->getProcess();
|
||||
|
||||
$this->assertFalse($proc->areEnvironmentVariablesInherited());
|
||||
}
|
||||
|
||||
public function testAddEnvironmentVariables()
|
||||
@@ -41,29 +46,12 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
->add('command')
|
||||
->setEnv('foo', 'bar2')
|
||||
->addEnvironmentVariables($env)
|
||||
->inheritEnvironmentVariables(false)
|
||||
->getProcess()
|
||||
;
|
||||
|
||||
$this->assertSame($env, $proc->getEnv());
|
||||
}
|
||||
|
||||
public function testProcessShouldInheritAndOverrideEnvironmentVars()
|
||||
{
|
||||
$_ENV['MY_VAR_1'] = 'foo';
|
||||
|
||||
$proc = ProcessBuilder::create()
|
||||
->setEnv('MY_VAR_1', 'bar')
|
||||
->add('foo')
|
||||
->getProcess();
|
||||
|
||||
unset($_ENV['MY_VAR_1']);
|
||||
|
||||
$env = $proc->getEnv();
|
||||
$this->assertArrayHasKey('MY_VAR_1', $env);
|
||||
$this->assertEquals('bar', $env['MY_VAR_1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
|
||||
*/
|
||||
@@ -103,14 +91,14 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$proc = $pb->setArguments(array('-v'))->getProcess();
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertEquals('"/usr/bin/php" "-v"', $proc->getCommandLine());
|
||||
$this->assertEquals('"/usr/bin/php" -v', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
|
||||
}
|
||||
|
||||
$proc = $pb->setArguments(array('-i'))->getProcess();
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertEquals('"/usr/bin/php" "-i"', $proc->getCommandLine());
|
||||
$this->assertEquals('"/usr/bin/php" -i', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
|
||||
}
|
||||
@@ -123,14 +111,14 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$proc = $pb->setArguments(array('-v'))->getProcess();
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertEquals('"/usr/bin/php" "composer.phar" "-v"', $proc->getCommandLine());
|
||||
$this->assertEquals('"/usr/bin/php" composer.phar -v', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
|
||||
}
|
||||
|
||||
$proc = $pb->setArguments(array('-i'))->getProcess();
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertEquals('"/usr/bin/php" "composer.phar" "-i"', $proc->getCommandLine());
|
||||
$this->assertEquals('"/usr/bin/php" composer.phar -i', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
|
||||
}
|
||||
@@ -142,7 +130,7 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$proc = $pb->getProcess();
|
||||
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertSame('^%"path"^% "foo \\" bar" "%baz%baz"', $proc->getCommandLine());
|
||||
$this->assertSame('""^%"path"^%"" "foo "" bar" ""^%"baz"^%"baz"', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
|
||||
}
|
||||
@@ -155,7 +143,7 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$proc = $pb->getProcess();
|
||||
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->assertSame('^%"prefix"^% "arg"', $proc->getCommandLine());
|
||||
$this->assertSame('""^%"prefix"^%"" arg', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
|
||||
}
|
||||
@@ -222,4 +210,17 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder = ProcessBuilder::create();
|
||||
$builder->setInput(array());
|
||||
}
|
||||
|
||||
public function testDoesNotPrefixExec()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test cannot run on Windows.');
|
||||
}
|
||||
|
||||
$builder = ProcessBuilder::create(array('command', '-v', 'ls'));
|
||||
$process = $builder->getProcess();
|
||||
$process->run();
|
||||
|
||||
$this->assertTrue($process->isSuccessful());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,31 +11,30 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
/**
|
||||
* @author Sebastian Marek <proofek@gmail.com>
|
||||
*/
|
||||
class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
class ProcessFailedExceptionTest extends 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 = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful'))->setConstructorArgs(array('php'))->getMock();
|
||||
$process->expects($this->once())
|
||||
->method('isSuccessful')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->setExpectedException(
|
||||
'\InvalidArgumentException',
|
||||
'Expected a failed process, but the given process was successful.'
|
||||
);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Expected a failed process, but the given process was successful.');
|
||||
} else {
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'Expected a failed process, but the given process was successful.');
|
||||
}
|
||||
|
||||
new ProcessFailedException($process);
|
||||
}
|
||||
@@ -53,11 +52,7 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
$errorOutput = 'FATAL: Unexpected error';
|
||||
$workingDirectory = getcwd();
|
||||
|
||||
$process = $this->getMock(
|
||||
'Symfony\Component\Process\Process',
|
||||
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
|
||||
array($cmd)
|
||||
);
|
||||
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'))->setConstructorArgs(array($cmd))->getMock();
|
||||
$process->expects($this->once())
|
||||
->method('isSuccessful')
|
||||
->will($this->returnValue(false));
|
||||
@@ -105,11 +100,7 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
$exitText = 'General error';
|
||||
$workingDirectory = getcwd();
|
||||
|
||||
$process = $this->getMock(
|
||||
'Symfony\Component\Process\Process',
|
||||
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
|
||||
array($cmd)
|
||||
);
|
||||
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'))->setConstructorArgs(array($cmd))->getMock();
|
||||
$process->expects($this->once())
|
||||
->method('isSuccessful')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\Exception\LogicException;
|
||||
use Symfony\Component\Process\Exception\ProcessTimedOutException;
|
||||
use Symfony\Component\Process\Exception\RuntimeException;
|
||||
@@ -22,7 +23,7 @@ use Symfony\Component\Process\Process;
|
||||
/**
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
*/
|
||||
class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
class ProcessTest extends TestCase
|
||||
{
|
||||
private static $phpBin;
|
||||
private static $process;
|
||||
@@ -33,12 +34,6 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$phpBin = new PhpExecutableFinder();
|
||||
self::$phpBin = getenv('SYMFONY_PROCESS_PHP_TEST_BINARY') ?: ('phpdbg' === PHP_SAPI ? 'php' : $phpBin->find());
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
// exec is mandatory to deal with sending a signal to the process
|
||||
// see https://github.com/symfony/symfony/issues/5030 about prepending
|
||||
// command with exec
|
||||
self::$phpBin = 'exec '.self::$phpBin;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
phpinfo(INFO_GENERAL);
|
||||
@@ -53,13 +48,31 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since Symfony 3.4 and will be removed in 4.0.
|
||||
*/
|
||||
public function testInvalidCwd()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('False-positive on Windows/appveyor.');
|
||||
}
|
||||
|
||||
// Check that it works fine if the CWD exists
|
||||
$cmd = new Process('echo test', __DIR__);
|
||||
$cmd->run();
|
||||
|
||||
$cmd = new Process('echo test', __DIR__.'/notfound/');
|
||||
$cmd->run();
|
||||
}
|
||||
|
||||
public function testThatProcessDoesNotThrowWarningDuringRun()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test is transient on Windows');
|
||||
}
|
||||
@trigger_error('Test Error', E_USER_NOTICE);
|
||||
$process = $this->getProcess(self::$phpBin." -r 'sleep(3)'");
|
||||
$process = $this->getProcessForCode('sleep(3)');
|
||||
$process->run();
|
||||
$actualError = error_get_last();
|
||||
$this->assertEquals('Test Error', $actualError['message']);
|
||||
@@ -102,7 +115,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testStopWithTimeoutIsActuallyWorking()
|
||||
{
|
||||
$p = $this->getProcess(self::$phpBin.' '.__DIR__.'/NonStopableProcess.php 30');
|
||||
$p = $this->getProcess(array(self::$phpBin, __DIR__.'/NonStopableProcess.php', 30));
|
||||
$p->start();
|
||||
|
||||
while (false === strpos($p->getOutput(), 'received')) {
|
||||
@@ -128,7 +141,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$expectedOutputSize = PipesInterface::CHUNK_SIZE * 2 + 2;
|
||||
|
||||
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
||||
$p = $this->getProcessForCode($code);
|
||||
|
||||
$p->start();
|
||||
|
||||
@@ -167,7 +180,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testProcessResponses($expected, $getter, $code)
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
||||
$p = $this->getProcessForCode($code);
|
||||
$p->run();
|
||||
|
||||
$this->assertSame($expected, $p->$getter());
|
||||
@@ -183,7 +196,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$expected = str_repeat(str_repeat('*', 1024), $size).'!';
|
||||
$expectedLength = (1024 * $size) + 1;
|
||||
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
||||
$p = $this->getProcessForCode($code);
|
||||
$p->setInput($expected);
|
||||
$p->run();
|
||||
|
||||
@@ -203,7 +216,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
fwrite($stream, $expected);
|
||||
rewind($stream);
|
||||
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
||||
$p = $this->getProcessForCode($code);
|
||||
$p->setInput($stream);
|
||||
$p->run();
|
||||
|
||||
@@ -219,7 +232,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
fwrite($stream, 'hello');
|
||||
rewind($stream);
|
||||
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);')));
|
||||
$p = $this->getProcessForCode('stream_copy_to_stream(STDIN, STDOUT);');
|
||||
$p->setInput($stream);
|
||||
$p->start(function ($type, $data) use ($stream) {
|
||||
if ('hello' === $data) {
|
||||
@@ -237,7 +250,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSetInputWhileRunningThrowsAnException()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
|
||||
$process = $this->getProcessForCode('sleep(30);');
|
||||
$process->start();
|
||||
try {
|
||||
$process->setInput('foobar');
|
||||
@@ -314,11 +327,11 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCallbackIsExecutedForOutput()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('echo \'foo\';')));
|
||||
$p = $this->getProcessForCode('echo \'foo\';');
|
||||
|
||||
$called = false;
|
||||
$p->run(function ($type, $buffer) use (&$called) {
|
||||
$called = $buffer === 'foo';
|
||||
$called = 'foo' === $buffer;
|
||||
});
|
||||
|
||||
$this->assertTrue($called, 'The callback should be executed with the output');
|
||||
@@ -326,12 +339,12 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCallbackIsExecutedForOutputWheneverOutputIsDisabled()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('echo \'foo\';')));
|
||||
$p = $this->getProcessForCode('echo \'foo\';');
|
||||
$p->disableOutput();
|
||||
|
||||
$called = false;
|
||||
$p->run(function ($type, $buffer) use (&$called) {
|
||||
$called = $buffer === 'foo';
|
||||
$called = 'foo' === $buffer;
|
||||
});
|
||||
|
||||
$this->assertTrue($called, 'The callback should be executed with the output');
|
||||
@@ -339,7 +352,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetErrorOutput()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
|
||||
$p = $this->getProcessForCode('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }');
|
||||
|
||||
$p->run();
|
||||
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
|
||||
@@ -347,7 +360,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFlushErrorOutput()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
|
||||
$p = $this->getProcessForCode('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }');
|
||||
|
||||
$p->run();
|
||||
$p->clearErrorOutput();
|
||||
@@ -361,7 +374,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$lock = tempnam(sys_get_temp_dir(), __FUNCTION__);
|
||||
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');')));
|
||||
$p = $this->getProcessForCode('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');');
|
||||
|
||||
$h = fopen($lock, 'w');
|
||||
flock($h, LOCK_EX);
|
||||
@@ -392,7 +405,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetOutput()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }')));
|
||||
$p = $this->getProcessForCode('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }');
|
||||
|
||||
$p->run();
|
||||
$this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
|
||||
@@ -400,7 +413,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFlushOutput()
|
||||
{
|
||||
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
|
||||
$p = $this->getProcessForCode('$n=0;while ($n<3) {echo \' foo \';$n++;}');
|
||||
|
||||
$p->run();
|
||||
$p->clearOutput();
|
||||
@@ -434,13 +447,16 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertGreaterThan(0, $process->getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group tty
|
||||
*/
|
||||
public function testTTYCommand()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Windows does not have /dev/tty support');
|
||||
}
|
||||
|
||||
$process = $this->getProcess('echo "foo" >> /dev/null && '.self::$phpBin.' -r "usleep(100000);"');
|
||||
$process = $this->getProcess('echo "foo" >> /dev/null && '.$this->getProcessForCode('usleep(100000);')->getCommandLine());
|
||||
$process->setTty(true);
|
||||
$process->start();
|
||||
$this->assertTrue($process->isRunning());
|
||||
@@ -449,6 +465,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group tty
|
||||
*/
|
||||
public function testTTYCommandExitCode()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
@@ -544,7 +563,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testStartIsNonBlocking()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
||||
$process = $this->getProcessForCode('usleep(500000);');
|
||||
$start = microtime(true);
|
||||
$process->start();
|
||||
$end = microtime(true);
|
||||
@@ -556,14 +575,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$process = $this->getProcess('echo foo');
|
||||
$process->run();
|
||||
$this->assertTrue(strlen($process->getOutput()) > 0);
|
||||
$this->assertGreaterThan(0, strlen($process->getOutput()));
|
||||
}
|
||||
|
||||
public function testGetExitCodeIsNullOnStart()
|
||||
{
|
||||
$this->skipIfNotEnhancedSigchild();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
|
||||
$process = $this->getProcessForCode('usleep(100000);');
|
||||
$this->assertNull($process->getExitCode());
|
||||
$process->start();
|
||||
$this->assertNull($process->getExitCode());
|
||||
@@ -575,7 +594,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->skipIfNotEnhancedSigchild();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
|
||||
$process = $this->getProcessForCode('usleep(100000);');
|
||||
$process->run();
|
||||
$this->assertEquals(0, $process->getExitCode());
|
||||
$process->start();
|
||||
@@ -595,7 +614,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testStatus()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
|
||||
$process = $this->getProcessForCode('usleep(100000);');
|
||||
$this->assertFalse($process->isRunning());
|
||||
$this->assertFalse($process->isStarted());
|
||||
$this->assertFalse($process->isTerminated());
|
||||
@@ -614,7 +633,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testStop()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(31);"');
|
||||
$process = $this->getProcessForCode('sleep(31);');
|
||||
$process->start();
|
||||
$this->assertTrue($process->isRunning());
|
||||
$process->stop();
|
||||
@@ -634,7 +653,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->skipIfNotEnhancedSigchild();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
|
||||
$process = $this->getProcessForCode('usleep(100000);');
|
||||
$process->start();
|
||||
|
||||
$this->assertFalse($process->isSuccessful());
|
||||
@@ -648,7 +667,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->skipIfNotEnhancedSigchild();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "throw new \Exception(\'BOUM\');"');
|
||||
$process = $this->getProcessForCode('throw new \Exception(\'BOUM\');');
|
||||
$process->run();
|
||||
$this->assertFalse($process->isSuccessful());
|
||||
}
|
||||
@@ -684,7 +703,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
$this->skipIfNotEnhancedSigchild();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(32);"');
|
||||
$process = $this->getProcessForCode('sleep(32);');
|
||||
$process->start();
|
||||
$process->stop();
|
||||
$this->assertTrue($process->hasBeenSignaled());
|
||||
@@ -702,7 +721,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
$this->skipIfNotEnhancedSigchild(false);
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(32.1)"');
|
||||
$process = $this->getProcessForCode('sleep(32.1);');
|
||||
$process->start();
|
||||
posix_kill($process->getPid(), 9); // SIGKILL
|
||||
|
||||
@@ -711,7 +730,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRestart()
|
||||
{
|
||||
$process1 = $this->getProcess(self::$phpBin.' -r "echo getmypid();"');
|
||||
$process1 = $this->getProcessForCode('echo getmypid();');
|
||||
$process1->run();
|
||||
$process2 = $process1->restart();
|
||||
|
||||
@@ -720,8 +739,8 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
// 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()));
|
||||
$this->assertInternalType('numeric', $process1->getOutput());
|
||||
$this->assertInternalType('numeric', $process2->getOutput());
|
||||
|
||||
// Ensure that restart returned a new process by check that the output is different
|
||||
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
|
||||
@@ -733,7 +752,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testRunProcessWithTimeout()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
|
||||
$process = $this->getProcessForCode('sleep(30);');
|
||||
$process->setTimeout(0.1);
|
||||
$start = microtime(true);
|
||||
try {
|
||||
@@ -747,6 +766,27 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
|
||||
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
|
||||
*/
|
||||
public function testIterateOverProcessWithTimeout()
|
||||
{
|
||||
$process = $this->getProcessForCode('sleep(30);');
|
||||
$process->setTimeout(0.1);
|
||||
$start = microtime(true);
|
||||
try {
|
||||
$process->start();
|
||||
foreach ($process as $buffer);
|
||||
$this->fail('A RuntimeException should have been raised');
|
||||
} catch (RuntimeException $e) {
|
||||
}
|
||||
|
||||
$this->assertLessThan(15, microtime(true) - $start);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
public function testCheckTimeoutOnNonStartedProcess()
|
||||
{
|
||||
$process = $this->getProcess('echo foo');
|
||||
@@ -766,7 +806,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCheckTimeoutOnStartedProcess()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(33);"');
|
||||
$process = $this->getProcessForCode('sleep(33);');
|
||||
$process->setTimeout(0.1);
|
||||
|
||||
$process->start();
|
||||
@@ -788,7 +828,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testIdleTimeout()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(34);"');
|
||||
$process = $this->getProcessForCode('sleep(34);');
|
||||
$process->setTimeout(60);
|
||||
$process->setIdleTimeout(0.1);
|
||||
|
||||
@@ -805,7 +845,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testIdleTimeoutNotExceededWhenOutputIsSent()
|
||||
{
|
||||
$process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('while (true) {echo \'foo \'; usleep(1000);}')));
|
||||
$process = $this->getProcessForCode('while (true) {echo \'foo \'; usleep(1000);}');
|
||||
$process->setTimeout(1);
|
||||
$process->start();
|
||||
|
||||
@@ -831,7 +871,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testStartAfterATimeout()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(35);"');
|
||||
$process = $this->getProcessForCode('sleep(35);');
|
||||
$process->setTimeout(0.1);
|
||||
|
||||
try {
|
||||
@@ -849,7 +889,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetPid()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(36);"');
|
||||
$process = $this->getProcessForCode('sleep(36);');
|
||||
$process->start();
|
||||
$this->assertGreaterThan(0, $process->getPid());
|
||||
$process->stop(0);
|
||||
@@ -873,7 +913,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSignal()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' '.__DIR__.'/SignalListener.php');
|
||||
$process = $this->getProcess(array(self::$phpBin, __DIR__.'/SignalListener.php'));
|
||||
$process->start();
|
||||
|
||||
while (false === strpos($process->getOutput(), 'Caught')) {
|
||||
@@ -922,7 +962,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
public function testMethodsThatNeedARunningProcess($method)
|
||||
{
|
||||
$process = $this->getProcess('foo');
|
||||
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('Symfony\Component\Process\Exception\LogicException');
|
||||
$this->expectExceptionMessage(sprintf('Process must be started before calling %s.', $method));
|
||||
} else {
|
||||
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
|
||||
}
|
||||
|
||||
$process->{$method}();
|
||||
}
|
||||
|
||||
@@ -944,7 +991,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMethodsThatNeedATerminatedProcess($method)
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(37);"');
|
||||
$process = $this->getProcessForCode('sleep(37);');
|
||||
$process->start();
|
||||
try {
|
||||
$process->{$method}();
|
||||
@@ -977,7 +1024,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('POSIX signals do not work on Windows');
|
||||
}
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(38);"');
|
||||
$process = $this->getProcessForCode('sleep(38);');
|
||||
$process->start();
|
||||
try {
|
||||
$process->signal($signal);
|
||||
@@ -1013,7 +1060,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testDisableOutputWhileRunningThrowsException()
|
||||
{
|
||||
$p = $this->getProcess(self::$phpBin.' -r "sleep(39);"');
|
||||
$p = $this->getProcessForCode('sleep(39);');
|
||||
$p->start();
|
||||
$p->disableOutput();
|
||||
}
|
||||
@@ -1024,7 +1071,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEnableOutputWhileRunningThrowsException()
|
||||
{
|
||||
$p = $this->getProcess(self::$phpBin.' -r "sleep(40);"');
|
||||
$p = $this->getProcessForCode('sleep(40);');
|
||||
$p->disableOutput();
|
||||
$p->start();
|
||||
$p->enableOutput();
|
||||
@@ -1076,7 +1123,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetOutputWhileDisabled($fetchMethod)
|
||||
{
|
||||
$p = $this->getProcess(self::$phpBin.' -r "sleep(41);"');
|
||||
$p = $this->getProcessForCode('sleep(41);');
|
||||
$p->disableOutput();
|
||||
$p->start();
|
||||
$p->{$fetchMethod}();
|
||||
@@ -1094,7 +1141,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testStopTerminatesProcessCleanly()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(42);"');
|
||||
$process = $this->getProcessForCode('echo 123; sleep(42);');
|
||||
$process->run(function () use ($process) {
|
||||
$process->stop();
|
||||
});
|
||||
@@ -1103,7 +1150,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testKillSignalTerminatesProcessCleanly()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(43);"');
|
||||
$process = $this->getProcessForCode('echo 123; sleep(43);');
|
||||
$process->run(function () use ($process) {
|
||||
$process->signal(9); // SIGKILL
|
||||
});
|
||||
@@ -1112,7 +1159,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTermSignalTerminatesProcessCleanly()
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(44);"');
|
||||
$process = $this->getProcessForCode('echo 123; sleep(44);');
|
||||
$process->run(function () use ($process) {
|
||||
$process->signal(15); // SIGTERM
|
||||
});
|
||||
@@ -1158,7 +1205,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testIncrementalOutputDoesNotRequireAnotherCall($stream, $method)
|
||||
{
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\''.$stream.'\', $n, 1); $n++; usleep(1000); }'), null, null, null, null);
|
||||
$process = $this->getProcessForCode('$n = 0; while ($n < 3) { file_put_contents(\''.$stream.'\', $n, 1); $n++; usleep(1000); }', null, null, null, null);
|
||||
$process->start();
|
||||
$result = '';
|
||||
$limit = microtime(true) + 3;
|
||||
@@ -1187,7 +1234,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
yield 'pong';
|
||||
};
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);'), null, null, $input());
|
||||
$process = $this->getProcessForCode('stream_copy_to_stream(STDIN, STDOUT);', null, null, $input());
|
||||
$process->run();
|
||||
$this->assertSame('pingpong', $process->getOutput());
|
||||
}
|
||||
@@ -1196,7 +1243,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$input = new InputStream();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo \'ping\'; stream_copy_to_stream(STDIN, STDOUT);'));
|
||||
$process = $this->getProcessForCode('echo \'ping\'; echo fread(STDIN, 4); echo fread(STDIN, 4);');
|
||||
$process->setInput($input);
|
||||
|
||||
$process->start(function ($type, $data) use ($input) {
|
||||
@@ -1230,7 +1277,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$input->onEmpty($stream);
|
||||
$input->write($stream());
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo fread(STDIN, 3);'));
|
||||
$process = $this->getProcessForCode('echo fread(STDIN, 3);');
|
||||
$process->setInput($input);
|
||||
$process->start(function ($type, $data) use ($input) {
|
||||
$input->close();
|
||||
@@ -1248,7 +1295,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$input->close();
|
||||
});
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);'));
|
||||
$process = $this->getProcessForCode('stream_copy_to_stream(STDIN, STDOUT);');
|
||||
$process->setInput($input);
|
||||
$process->start();
|
||||
$input->write('ping');
|
||||
@@ -1260,9 +1307,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$i = 0;
|
||||
$input = new InputStream();
|
||||
$input->onEmpty(function () use (&$i) {++$i;});
|
||||
$input->onEmpty(function () use (&$i) { ++$i; });
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo 123; echo fread(STDIN, 1); echo 456;'));
|
||||
$process = $this->getProcessForCode('echo 123; echo fread(STDIN, 1); echo 456;');
|
||||
$process->setInput($input);
|
||||
$process->start(function ($type, $data) use ($input) {
|
||||
if ('123' === $data) {
|
||||
@@ -1279,7 +1326,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$input = new InputStream();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('fwrite(STDOUT, 123); fwrite(STDERR, 234); flush(); usleep(10000); fwrite(STDOUT, fread(STDIN, 3)); fwrite(STDERR, 456);'));
|
||||
$process = $this->getProcessForCode('fwrite(STDOUT, 123); fwrite(STDERR, 234); flush(); usleep(10000); fwrite(STDOUT, fread(STDIN, 3)); fwrite(STDERR, 456);');
|
||||
$process->setInput($input);
|
||||
$process->start();
|
||||
$output = array();
|
||||
@@ -1315,7 +1362,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$input = new InputStream();
|
||||
|
||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('fwrite(STDOUT, fread(STDIN, 3));'));
|
||||
$process = $this->getProcessForCode('fwrite(STDOUT, fread(STDIN, 3));');
|
||||
$process->setInput($input);
|
||||
$process->start();
|
||||
$output = array();
|
||||
@@ -1349,8 +1396,8 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testChainedProcesses()
|
||||
{
|
||||
$p1 = new Process(self::$phpBin.' -r '.escapeshellarg('fwrite(STDERR, 123); fwrite(STDOUT, 456);'));
|
||||
$p2 = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);')));
|
||||
$p1 = $this->getProcessForCode('fwrite(STDERR, 123); fwrite(STDOUT, 456);');
|
||||
$p2 = $this->getProcessForCode('stream_copy_to_stream(STDIN, STDOUT);');
|
||||
$p2->setInput($p1);
|
||||
|
||||
$p1->start();
|
||||
@@ -1362,6 +1409,151 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame('456', $p2->getOutput());
|
||||
}
|
||||
|
||||
public function testSetBadEnv()
|
||||
{
|
||||
$process = $this->getProcess('echo hello');
|
||||
$process->setEnv(array('bad%%' => '123'));
|
||||
$process->inheritEnvironmentVariables(true);
|
||||
|
||||
$process->run();
|
||||
|
||||
$this->assertSame('hello'.PHP_EOL, $process->getOutput());
|
||||
$this->assertSame('', $process->getErrorOutput());
|
||||
}
|
||||
|
||||
public function testEnvBackupDoesNotDeleteExistingVars()
|
||||
{
|
||||
putenv('existing_var=foo');
|
||||
$_ENV['existing_var'] = 'foo';
|
||||
$process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"');
|
||||
$process->setEnv(array('existing_var' => 'bar', 'new_test_var' => 'foo'));
|
||||
$process->inheritEnvironmentVariables();
|
||||
|
||||
$process->run();
|
||||
|
||||
$this->assertSame('foo', $process->getOutput());
|
||||
$this->assertSame('foo', getenv('existing_var'));
|
||||
$this->assertFalse(getenv('new_test_var'));
|
||||
|
||||
putenv('existing_var');
|
||||
unset($_ENV['existing_var']);
|
||||
}
|
||||
|
||||
public function testEnvIsInherited()
|
||||
{
|
||||
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ', 'EMPTY' => ''));
|
||||
|
||||
putenv('FOO=BAR');
|
||||
$_ENV['FOO'] = 'BAR';
|
||||
|
||||
$process->run();
|
||||
|
||||
$expected = array('BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR');
|
||||
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
|
||||
|
||||
$this->assertEquals($expected, $env);
|
||||
|
||||
putenv('FOO');
|
||||
unset($_ENV['FOO']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInheritEnvDisabled()
|
||||
{
|
||||
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ'));
|
||||
|
||||
putenv('FOO=BAR');
|
||||
$_ENV['FOO'] = 'BAR';
|
||||
|
||||
$this->assertSame($process, $process->inheritEnvironmentVariables(false));
|
||||
$this->assertFalse($process->areEnvironmentVariablesInherited());
|
||||
|
||||
$process->run();
|
||||
|
||||
$expected = array('BAR' => 'BAZ', 'FOO' => 'BAR');
|
||||
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
|
||||
unset($expected['FOO']);
|
||||
|
||||
$this->assertSame($expected, $env);
|
||||
|
||||
putenv('FOO');
|
||||
unset($_ENV['FOO']);
|
||||
}
|
||||
|
||||
public function testGetCommandLine()
|
||||
{
|
||||
$p = new Process(array('/usr/bin/php'));
|
||||
|
||||
$expected = '\\' === DIRECTORY_SEPARATOR ? '"/usr/bin/php"' : "'/usr/bin/php'";
|
||||
$this->assertSame($expected, $p->getCommandLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideEscapeArgument
|
||||
*/
|
||||
public function testEscapeArgument($arg)
|
||||
{
|
||||
$p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg));
|
||||
$p->run();
|
||||
|
||||
$this->assertSame($arg, $p->getOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideEscapeArgument
|
||||
* @group legacy
|
||||
*/
|
||||
public function testEscapeArgumentWhenInheritEnvDisabled($arg)
|
||||
{
|
||||
$p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg), null, array('BAR' => 'BAZ'));
|
||||
$p->inheritEnvironmentVariables(false);
|
||||
$p->run();
|
||||
|
||||
$this->assertSame($arg, $p->getOutput());
|
||||
}
|
||||
|
||||
public function testRawCommandLine()
|
||||
{
|
||||
$p = new Process(sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);')));
|
||||
$p->run();
|
||||
|
||||
$expected = <<<EOTXT
|
||||
Array
|
||||
(
|
||||
[0] => -
|
||||
[1] => a
|
||||
[2] =>
|
||||
[3] => b
|
||||
)
|
||||
|
||||
EOTXT;
|
||||
$this->assertSame($expected, str_replace('Standard input code', '-', $p->getOutput()));
|
||||
}
|
||||
|
||||
public function provideEscapeArgument()
|
||||
{
|
||||
yield array('a"b%c%');
|
||||
yield array('a"b^c^');
|
||||
yield array("a\nb'c");
|
||||
yield array('a^b c!');
|
||||
yield array("a!b\tc");
|
||||
yield array('a\\\\"\\"');
|
||||
yield array('éÉèÈàÀöä');
|
||||
}
|
||||
|
||||
public function testEnvArgument()
|
||||
{
|
||||
$env = array('FOO' => 'Foo', 'BAR' => 'Bar');
|
||||
$cmd = '\\' === DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ';
|
||||
$p = new Process($cmd, null, $env);
|
||||
$p->run(null, array('BAR' => 'baR', 'BAZ' => 'baZ'));
|
||||
|
||||
$this->assertSame('Foo baR baZ', rtrim($p->getOutput()));
|
||||
$this->assertSame($env, $p->getEnv());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $commandline
|
||||
* @param null|string $cwd
|
||||
@@ -1372,9 +1564,10 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @return Process
|
||||
*/
|
||||
private function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
|
||||
private function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60)
|
||||
{
|
||||
$process = new Process($commandline, $cwd, $env, $input, $timeout, $options);
|
||||
$process = new Process($commandline, $cwd, $env, $input, $timeout);
|
||||
$process->inheritEnvironmentVariables();
|
||||
|
||||
if (false !== $enhance = getenv('ENHANCE_SIGCHLD')) {
|
||||
try {
|
||||
@@ -1398,13 +1591,26 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
return self::$process = $process;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Process
|
||||
*/
|
||||
private function getProcessForCode($code, $cwd = null, array $env = null, $input = null, $timeout = 60)
|
||||
{
|
||||
return $this->getProcess(array(self::$phpBin, '-r', $code), $cwd, $env, $input, $timeout);
|
||||
}
|
||||
|
||||
private function skipIfNotEnhancedSigchild($expectException = true)
|
||||
{
|
||||
if (self::$sigchild) {
|
||||
if (!$expectException) {
|
||||
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
|
||||
} elseif (self::$notEnhancedSigchild) {
|
||||
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('Symfony\Component\Process\Exception\RuntimeException');
|
||||
$this->expectExceptionMessage('This PHP has been compiled with --enable-sigchild.');
|
||||
} else {
|
||||
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\ProcessUtils;
|
||||
|
||||
class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ProcessUtilsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataArguments
|
||||
@@ -43,6 +47,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
|
||||
array("''", ''),
|
||||
array("'with\\trailingbs\\'", 'with\trailingbs\\'),
|
||||
array("'withNonAsciiAccentLikeéÉèÈàÀöä'", 'withNonAsciiAccentLikeéÉèÈàÀöä'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
pcntl_signal(SIGUSR1, function () {echo 'SIGUSR1'; exit;});
|
||||
pcntl_signal(SIGUSR1, function () { echo 'SIGUSR1'; exit; });
|
||||
|
||||
echo 'Caught ';
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
"php": "^5.5.9|>=7.0.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\Process\\": "" },
|
||||
@@ -27,7 +27,7 @@
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.1-dev"
|
||||
"dev-master": "3.4-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
|
||||
Reference in New Issue
Block a user