Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -1,6 +1,30 @@
CHANGELOG
=========
4.1.0
-----
* added the `Process::isTtySupported()` method that allows to check for TTY support
* made `PhpExecutableFinder` look for the `PHP_BINARY` env var when searching the php binary
* added the `ProcessSignaledException` class to properly catch signaled process errors
4.0.0
-----
* environment variables will always be inherited
* added a second `array $env = array()` argument to the `start()`, `run()`,
`mustRun()`, and `restart()` methods of the `Process` class
* added a second `array $env = array()` argument to the `start()` method of the
`PhpProcess` class
* the `ProcessUtils::escapeArgument()` method has been removed
* the `areEnvironmentVariablesInherited()`, `getOptions()`, and `setOptions()`
methods of the `Process` class have been removed
* support for passing `proc_open()` options has been removed
* removed the `ProcessBuilder` class, use the `Process` class instead
* removed the `getEnhanceWindowsCompatibility()` and `setEnhanceWindowsCompatibility()` methods of the `Process` class
* passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is not
supported anymore
3.4.0
-----

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
use Symfony\Component\Process\Process;
/**
* Exception that is thrown when a process has been signaled.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
final class ProcessSignaledException extends RuntimeException
{
private $process;
public function __construct(Process $process)
{
$this->process = $process;
parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
}
public function getProcess(): Process
{
return $this->process;
}
public function getSignal(): int
{
return $this->getProcess()->getTermSignal();
}
}

View File

@@ -26,7 +26,7 @@ class ProcessTimedOutException extends RuntimeException
private $process;
private $timeoutType;
public function __construct(Process $process, $timeoutType)
public function __construct(Process $process, int $timeoutType)
{
$this->process = $process;
$this->timeoutType = $timeoutType;

View File

@@ -35,14 +35,17 @@ class PhpExecutableFinder
*/
public function find($includeArgs = true)
{
if ($php = getenv('PHP_BINARY')) {
if (!is_executable($php)) {
return false;
}
return $php;
}
$args = $this->findArguments();
$args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
// HHVM support
if (\defined('HHVM_VERSION')) {
return (getenv('PHP_BINARY') ?: PHP_BINARY).$args;
}
// PHP_BINARY return the current sapi executable
if (PHP_BINARY && \in_array(\PHP_SAPI, array('cli', 'cli-server', 'phpdbg'), true)) {
return PHP_BINARY.$args;
@@ -82,10 +85,7 @@ class PhpExecutableFinder
public function findArguments()
{
$arguments = array();
if (\defined('HHVM_VERSION')) {
$arguments[] = '--php';
} elseif ('phpdbg' === \PHP_SAPI) {
if ('phpdbg' === \PHP_SAPI) {
$arguments[] = '-qrr';
}

View File

@@ -29,9 +29,8 @@ class PhpProcess extends Process
* @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 = null)
public function __construct(string $script, string $cwd = null, array $env = null, int $timeout = 60)
{
$executableFinder = new PhpExecutableFinder();
if (false === $php = $executableFinder->find(false)) {
@@ -46,11 +45,8 @@ class PhpProcess extends Process
$php[] = $file;
$script = null;
}
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);
parent::__construct($php, $cwd, $env, $script, $timeout);
}
/**
@@ -64,12 +60,11 @@ class PhpProcess extends Process
/**
* {@inheritdoc}
*/
public function start(callable $callback = null/*, array $env = array()*/)
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, $env);
}

View File

@@ -26,11 +26,11 @@ class UnixPipes extends AbstractPipes
private $ptyMode;
private $haveReadSupport;
public function __construct($ttyMode, $ptyMode, $input, $haveReadSupport)
public function __construct(?bool $ttyMode, bool $ptyMode, $input, bool $haveReadSupport)
{
$this->ttyMode = (bool) $ttyMode;
$this->ptyMode = (bool) $ptyMode;
$this->haveReadSupport = (bool) $haveReadSupport;
$this->ttyMode = $ttyMode;
$this->ptyMode = $ptyMode;
$this->haveReadSupport = $haveReadSupport;
parent::__construct($input);
}

View File

@@ -34,9 +34,9 @@ class WindowsPipes extends AbstractPipes
);
private $haveReadSupport;
public function __construct($input, $haveReadSupport)
public function __construct($input, bool $haveReadSupport)
{
$this->haveReadSupport = (bool) $haveReadSupport;
$this->haveReadSupport = $haveReadSupport;
if ($this->haveReadSupport) {
// Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.

View File

@@ -14,6 +14,7 @@ namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Pipes\PipesInterface;
@@ -58,22 +59,18 @@ class Process implements \IteratorAggregate
private $lastOutputTime;
private $timeout;
private $idleTimeout;
private $options = array('suppress_errors' => true);
private $exitcode;
private $fallbackStatus = array();
private $processInformation;
private $outputDisabled = false;
private $stdout;
private $stderr;
private $enhanceWindowsCompatibility = true;
private $enhanceSigchildCompatibility;
private $process;
private $status = self::STATUS_READY;
private $incrementalOutputOffset = 0;
private $incrementalErrorOutputOffset = 0;
private $tty;
private $pty;
private $inheritEnv = false;
private $useFileHandles = false;
/** @var PipesInterface */
@@ -137,11 +134,10 @@ class Process implements \IteratorAggregate
* @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
* @param int|float|null $timeout The timeout in seconds or null to disable
* @param array $options An array of options for proc_open
*
* @throws RuntimeException When proc_open is not installed
*/
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null)
public function __construct($commandline, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
if (!\function_exists('proc_open')) {
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
@@ -165,11 +161,6 @@ class Process implements \IteratorAggregate
$this->setTimeout($timeout);
$this->useFileHandles = '\\' === \DIRECTORY_SEPARATOR;
$this->pty = false;
$this->enhanceSigchildCompatibility = '\\' !== \DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
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()
@@ -202,11 +193,10 @@ class Process implements \IteratorAggregate
* @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
* @final
*/
public function run($callback = null/*, array $env = array()*/)
public function run(callable $callback = null, array $env = array()): int
{
$env = 1 < \func_num_args() ? func_get_arg(1) : null;
$this->start($callback, $env);
return $this->wait();
@@ -223,18 +213,12 @@ class Process implements \IteratorAggregate
*
* @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
* @final
*/
public function mustRun(callable $callback = null/*, array $env = array()*/)
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, $env)) {
throw new ProcessFailedException($this);
}
@@ -262,29 +246,17 @@ class Process implements \IteratorAggregate
* @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/*, array $env = array()*/)
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()[1]->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;
if (\is_array($commandline = $this->commandline)) {
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
@@ -295,26 +267,17 @@ class Process implements \IteratorAggregate
}
}
if (null === $env) {
$env = $this->env;
} else {
if ($this->env) {
$env += $this->env;
}
$inheritEnv = true;
if ($this->env) {
$env += $this->env;
}
$env += $this->getDefaultEnv();
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) {
$this->options['bypass_shell'] = true;
$options = array('suppress_errors' => true);
if ('\\' === \DIRECTORY_SEPARATOR) {
$options['bypass_shell'] = true;
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
} elseif (!$this->useFileHandles && $this->isSigchildEnabled()) {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors[3] = array('pipe', 'w');
@@ -326,22 +289,19 @@ class Process implements \IteratorAggregate
// @see : https://bugs.php.net/69442
$ptsWorkaround = fopen(__FILE__, 'r');
}
if (\defined('HHVM_VERSION')) {
$envPairs = $env;
} else {
$envPairs = array();
foreach ($env as $k => $v) {
if (false !== $v) {
$envPairs[] = $k.'='.$v;
}
$envPairs = array();
foreach ($env as $k => $v) {
if (false !== $v) {
$envPairs[] = $k.'='.$v;
}
}
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);
throw new RuntimeException('The provided cwd does not exist.');
}
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $options);
if (!\is_resource($this->process)) {
throw new RuntimeException('Unable to launch a new process.');
@@ -376,14 +336,13 @@ class Process implements \IteratorAggregate
*
* @see start()
*
* @final since version 3.3
* @final
*/
public function restart(callable $callback = null/*, array $env = array()*/)
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, $env);
@@ -431,7 +390,7 @@ class Process implements \IteratorAggregate
}
if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
throw new ProcessSignaledException($this);
}
return $this->exitcode;
@@ -693,15 +652,9 @@ class Process implements \IteratorAggregate
* Returns the exit code returned by the process.
*
* @return null|int The exit status code, null if the Process is not terminated
*
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
*/
public function getExitCode()
{
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
}
$this->updateStatus(false);
return $this->exitcode;
@@ -744,17 +697,12 @@ class Process implements \IteratorAggregate
*
* @return bool
*
* @throws RuntimeException In case --enable-sigchild is activated
* @throws LogicException In case the process is not terminated
* @throws LogicException In case the process is not terminated
*/
public function hasBeenSignaled()
{
$this->requireProcessIsTerminated(__FUNCTION__);
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
return $this->processInformation['signaled'];
}
@@ -772,7 +720,7 @@ class Process implements \IteratorAggregate
{
$this->requireProcessIsTerminated(__FUNCTION__);
if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
@@ -904,10 +852,8 @@ class Process implements \IteratorAggregate
* Adds a line to the STDOUT stream.
*
* @internal
*
* @param string $line The line to append
*/
public function addOutput($line)
public function addOutput(string $line)
{
$this->lastOutputTime = microtime(true);
@@ -920,10 +866,8 @@ class Process implements \IteratorAggregate
* Adds a line to the STDERR stream.
*
* @internal
*
* @param string $line The line to append
*/
public function addErrorOutput($line)
public function addErrorOutput(string $line)
{
$this->lastOutputTime = microtime(true);
@@ -1031,16 +975,9 @@ class Process implements \IteratorAggregate
if ('\\' === \DIRECTORY_SEPARATOR && $tty) {
throw new RuntimeException('TTY mode is not supported on Windows platform.');
}
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.');
}
if ($tty && !self::isTtySupported()) {
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
}
$this->tty = (bool) $tty;
@@ -1181,108 +1118,6 @@ class Process implements \IteratorAggregate
return $this;
}
/**
* 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;
}
/**
* Sets the options for proc_open.
*
* @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;
}
/**
* Gets whether or not Windows compatibility is enabled.
*
* 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;
}
/**
* Sets whether or not Windows compatibility is enabled.
*
* @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;
}
/**
* 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;
}
/**
* 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 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.
*
@@ -1293,28 +1128,12 @@ class Process implements \IteratorAggregate
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);
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
}
$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.
*
@@ -1342,6 +1161,20 @@ class Process implements \IteratorAggregate
}
}
/**
* Returns whether TTY is supported on the current operating system.
*/
public static function isTtySupported(): bool
{
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);
}
return $isTtySupported;
}
/**
* Returns whether PTY is supported on the current operating system.
*
@@ -1364,10 +1197,8 @@ class Process implements \IteratorAggregate
/**
* Creates the descriptors needed by the proc_open.
*
* @return array
*/
private function getDescriptors()
private function getDescriptors(): array
{
if ($this->input instanceof \Iterator) {
$this->input->rewind();
@@ -1432,7 +1263,7 @@ class Process implements \IteratorAggregate
$this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running);
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
if ($this->fallbackStatus && $this->isSigchildEnabled()) {
$this->processInformation = $this->fallbackStatus + $this->processInformation;
}
@@ -1452,7 +1283,7 @@ class Process implements \IteratorAggregate
return self::$sigchild;
}
if (!\function_exists('phpinfo') || \defined('HHVM_VERSION')) {
if (!\function_exists('phpinfo')) {
return self::$sigchild = false;
}
@@ -1470,7 +1301,7 @@ class Process implements \IteratorAggregate
*
* @throws LogicException in case output has been disabled or process is not started
*/
private function readPipesForOutput($caller, $blocking = false)
private function readPipesForOutput(string $caller, bool $blocking = false)
{
if ($this->outputDisabled) {
throw new LogicException('Output has been disabled.');
@@ -1484,13 +1315,9 @@ class Process implements \IteratorAggregate
/**
* Validates and returns the filtered timeout.
*
* @param int|float|null $timeout
*
* @return float|null
*
* @throws InvalidArgumentException if the given timeout is a negative number
*/
private function validateTimeout($timeout)
private function validateTimeout(?float $timeout): ?float
{
$timeout = (float) $timeout;
@@ -1509,7 +1336,7 @@ class Process implements \IteratorAggregate
* @param bool $blocking Whether to use blocking calls or not
* @param bool $close Whether to close file handles or not
*/
private function readPipes($blocking, $close)
private function readPipes(bool $blocking, bool $close)
{
$result = $this->processPipes->readAndWrite($blocking, $close);
@@ -1528,7 +1355,7 @@ class Process implements \IteratorAggregate
*
* @return int The exitcode
*/
private function close()
private function close(): int
{
$this->processPipes->close();
if (\is_resource($this->process)) {
@@ -1541,7 +1368,7 @@ class Process implements \IteratorAggregate
if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
// if process has been signaled, no exitcode but a valid termsig, apply Unix convention
$this->exitcode = 128 + $this->processInformation['termsig'];
} elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
} elseif ($this->isSigchildEnabled()) {
$this->processInformation['signaled'] = true;
$this->processInformation['termsig'] = -1;
}
@@ -1586,7 +1413,7 @@ class Process implements \IteratorAggregate
* @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
* @throws RuntimeException In case of failure
*/
private function doSignal($signal, $throwException)
private function doSignal(int $signal, bool $throwException): bool
{
if (null === $pid = $this->getPid()) {
if ($throwException) {
@@ -1606,7 +1433,7 @@ class Process implements \IteratorAggregate
return false;
}
} else {
if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) {
if (!$this->isSigchildEnabled()) {
$ok = @proc_terminate($this->process, $signal);
} elseif (\function_exists('posix_kill')) {
$ok = @posix_kill($pid, $signal);
@@ -1622,7 +1449,7 @@ class Process implements \IteratorAggregate
}
}
$this->latestSignal = (int) $signal;
$this->latestSignal = $signal;
$this->fallbackStatus['signaled'] = true;
$this->fallbackStatus['exitcode'] = -1;
$this->fallbackStatus['termsig'] = $this->latestSignal;
@@ -1630,7 +1457,7 @@ class Process implements \IteratorAggregate
return true;
}
private function prepareWindowsCommandLine($cmd, array &$env)
private function prepareWindowsCommandLine(string $cmd, array &$env)
{
$uid = uniqid('', true);
$varCount = 0;
@@ -1679,11 +1506,9 @@ class Process implements \IteratorAggregate
/**
* 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
*/
private function requireProcessIsStarted($functionName)
private function requireProcessIsStarted(string $functionName)
{
if (!$this->isStarted()) {
throw new LogicException(sprintf('Process must be started before calling %s.', $functionName));
@@ -1693,11 +1518,9 @@ class Process implements \IteratorAggregate
/**
* Ensures the process is terminated, throws a LogicException if the process has a status different than `terminated`.
*
* @param string $functionName The function name that was called
*
* @throws LogicException if the process is not yet terminated
*/
private function requireProcessIsTerminated($functionName)
private function requireProcessIsTerminated(string $functionName)
{
if (!$this->isTerminated()) {
throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
@@ -1706,12 +1529,8 @@ class Process implements \IteratorAggregate
/**
* 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)
private function escapeArgument(string $argument): string
{
if ('\\' !== \DIRECTORY_SEPARATOR) {
return "'".str_replace("'", "'\\''", $argument)."'";

View File

@@ -1,280 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
@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;
/**
* @author Kris Wallsmith <kris@symfony.com>
*
* @deprecated since version 3.4, to be removed in 4.0. Use the Process class instead.
*/
class ProcessBuilder
{
private $arguments;
private $cwd;
private $env = array();
private $input;
private $timeout = 60;
private $options;
private $inheritEnv = true;
private $prefix = array();
private $outputDisabled = false;
/**
* @param string[] $arguments An array of arguments
*/
public function __construct(array $arguments = array())
{
$this->arguments = $arguments;
}
/**
* Creates a process builder instance.
*
* @param string[] $arguments An array of arguments
*
* @return static
*/
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 $this
*/
public function add($argument)
{
$this->arguments[] = $argument;
return $this;
}
/**
* Adds a prefix to the command string.
*
* The prefix is preserved when resetting arguments.
*
* @param string|array $prefix A command prefix or an array of command prefixes
*
* @return $this
*/
public function setPrefix($prefix)
{
$this->prefix = \is_array($prefix) ? $prefix : array($prefix);
return $this;
}
/**
* Sets the arguments of the process.
*
* Arguments must not be escaped.
* Previous arguments are removed.
*
* @param string[] $arguments
*
* @return $this
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
/**
* Sets the working directory.
*
* @param null|string $cwd The working directory
*
* @return $this
*/
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;
return $this;
}
/**
* Sets whether environment variables will be inherited or not.
*
* @param bool $inheritEnv
*
* @return $this
*/
public function inheritEnvironmentVariables($inheritEnv = true)
{
$this->inheritEnv = $inheritEnv;
return $this;
}
/**
* Sets an environment variable.
*
* Setting a variable overrides its previous value. Use `null` to unset a
* defined environment variable.
*
* @param string $name The variable name
* @param null|string $value The variable value
*
* @return $this
*/
public function setEnv($name, $value)
{
$this->env[$name] = $value;
return $this;
}
/**
* Adds a set of environment variables.
*
* Already existing environment variables with the same name will be
* overridden by the new values passed to this method. Pass `null` to unset
* a variable.
*
* @param array $variables The variables
*
* @return $this
*/
public function addEnvironmentVariables(array $variables)
{
$this->env = array_replace($this->env, $variables);
return $this;
}
/**
* Sets the input of the process.
*
* @param resource|string|int|float|bool|\Traversable|null $input The input content
*
* @return $this
*
* @throws InvalidArgumentException In case the argument is invalid
*/
public function setInput($input)
{
$this->input = ProcessUtils::validateInput(__METHOD__, $input);
return $this;
}
/**
* Sets the process timeout.
*
* To disable the timeout, set this value to null.
*
* @param float|null $timeout
*
* @return $this
*
* @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;
}
/**
* Adds a proc_open option.
*
* @param string $name The option name
* @param string $value The option value
*
* @return $this
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;
return $this;
}
/**
* Disables fetching output and error output from the underlying process.
*
* @return $this
*/
public function disableOutput()
{
$this->outputDisabled = true;
return $this;
}
/**
* Enables fetching output and error output from the underlying process.
*
* @return $this
*/
public function enableOutput()
{
$this->outputDisabled = false;
return $this;
}
/**
* Creates a Process instance and returns it.
*
* @return Process
*
* @throws LogicException In case no arguments have been provided
*/
public function getProcess()
{
if (0 === \count($this->prefix) && 0 === \count($this->arguments)) {
throw new LogicException('You must add() command arguments before calling getProcess().');
}
$arguments = array_merge($this->prefix, $this->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) {
$process->inheritEnvironmentVariables();
}
if ($this->outputDisabled) {
$process->disableOutput();
}
return $process;
}
}

View File

@@ -29,55 +29,6 @@ class ProcessUtils
{
}
/**
* Escapes a string to be used as a shell argument.
*
* @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
//@see https://bugs.php.net/bug.php?id=49446
if ('\\' === \DIRECTORY_SEPARATOR) {
if ('' === $argument) {
return escapeshellarg($argument);
}
$escapedArgument = '';
$quote = false;
foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
// Avoid environment variable expansion
$escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
} else {
// escape trailing backslash
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
}
}
if ($quote) {
$escapedArgument = '"'.$escapedArgument.'"';
}
return $escapedArgument;
}
return "'".str_replace("'", "'\\''", $argument)."'";
}
/**
* Validates and normalizes a Process input.
*
@@ -115,9 +66,4 @@ class ProcessUtils
return $input;
}
private static function isSurroundedBy($arg, $char)
{
return 2 < \strlen($arg) && $char === $arg[0] && $char === $arg[\strlen($arg) - 1];
}
}

View File

@@ -91,7 +91,7 @@ class ExecutableFinderTest extends TestCase
$this->markTestSkipped('Cannot test when open_basedir is set');
}
$this->iniSet('open_basedir', \dirname(PHP_BINARY).(!\defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
$this->iniSet('open_basedir', \dirname(PHP_BINARY).PATH_SEPARATOR.'/');
$finder = new ExecutableFinder();
$result = $finder->find($this->getPhpBinaryName());
@@ -109,7 +109,7 @@ class ExecutableFinderTest extends TestCase
}
$this->setPath('');
$this->iniSet('open_basedir', PHP_BINARY.(!\defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
$this->iniSet('open_basedir', PHP_BINARY.PATH_SEPARATOR.'/');
$finder = new ExecutableFinder();
$result = $finder->find($this->getPhpBinaryName(), false);

View File

@@ -24,10 +24,6 @@ class PhpExecutableFinderTest extends TestCase
*/
public function testFind()
{
if (\defined('HHVM_VERSION')) {
$this->markTestSkipped('Should not be executed in HHVM context.');
}
$f = new PhpExecutableFinder();
$current = PHP_BINARY;
@@ -37,23 +33,6 @@ class PhpExecutableFinderTest extends TestCase
$this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
}
/**
* tests find() with the env var / constant PHP_BINARY with HHVM.
*/
public function testFindWithHHVM()
{
if (!\defined('HHVM_VERSION')) {
$this->markTestSkipped('Should be executed in HHVM context.');
}
$f = new PhpExecutableFinder();
$current = getenv('PHP_BINARY') ?: PHP_BINARY;
$this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
$this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
}
/**
* tests find() with the env var PHP_PATH.
*/
@@ -61,9 +40,7 @@ class PhpExecutableFinderTest extends TestCase
{
$f = new PhpExecutableFinder();
if (\defined('HHVM_VERSION')) {
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
} elseif ('phpdbg' === \PHP_SAPI) {
if ('phpdbg' === \PHP_SAPI) {
$this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
} else {
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');

View File

@@ -1,226 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\ProcessBuilder;
/**
* @group legacy
*/
class ProcessBuilderTest extends TestCase
{
public function testInheritEnvironmentVars()
{
$proc = ProcessBuilder::create()
->add('foo')
->getProcess();
$this->assertTrue($proc->areEnvironmentVariablesInherited());
$proc = ProcessBuilder::create()
->add('foo')
->inheritEnvironmentVariables(false)
->getProcess();
$this->assertFalse($proc->areEnvironmentVariablesInherited());
}
public function testAddEnvironmentVariables()
{
$pb = new ProcessBuilder();
$env = array(
'foo' => 'bar',
'foo2' => 'bar2',
);
$proc = $pb
->add('command')
->setEnv('foo', 'bar2')
->addEnvironmentVariables($env)
->getProcess()
;
$this->assertSame($env, $proc->getEnv());
}
/**
* @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 ('\\' === \DIRECTORY_SEPARATOR) {
$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());
} else {
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
}
}
public function testArrayPrefixesArePrependedToAllGeneratedProcess()
{
$pb = new ProcessBuilder();
$pb->setPrefix(array('/usr/bin/php', 'composer.phar'));
$proc = $pb->setArguments(array('-v'))->getProcess();
if ('\\' === \DIRECTORY_SEPARATOR) {
$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());
} else {
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
}
}
public function testShouldEscapeArguments()
{
$pb = new ProcessBuilder(array('%path%', 'foo " bar', '%baz%baz'));
$proc = $pb->getProcess();
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->assertSame('""^%"path"^%"" "foo "" bar" ""^%"baz"^%"baz"', $proc->getCommandLine());
} else {
$this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
}
}
public function testShouldEscapeArgumentsAndPrefix()
{
$pb = new ProcessBuilder(array('arg'));
$pb->setPrefix('%prefix%');
$proc = $pb->getProcess();
if ('\\' === \DIRECTORY_SEPARATOR) {
$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 ('\\' === \DIRECTORY_SEPARATOR) {
$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 ('\\' === \DIRECTORY_SEPARATOR) {
$this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
} else {
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
}
}
public function testShouldReturnProcessWithDisabledOutput()
{
$process = ProcessBuilder::create(array('/usr/bin/php'))
->disableOutput()
->getProcess();
$this->assertTrue($process->isOutputDisabled());
}
public function testShouldReturnProcessWithEnabledOutput()
{
$process = ProcessBuilder::create(array('/usr/bin/php'))
->disableOutput()
->enableOutput()
->getProcess();
$this->assertFalse($process->isOutputDisabled());
}
/**
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
* @expectedExceptionMessage Symfony\Component\Process\ProcessBuilder::setInput only accepts strings, Traversable objects or stream resources.
*/
public function testInvalidInput()
{
$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());
}
}

View File

@@ -28,7 +28,6 @@ class ProcessTest extends TestCase
private static $phpBin;
private static $process;
private static $sigchild;
private static $notEnhancedSigchild = false;
public static function setUpBeforeClass()
{
@@ -49,19 +48,19 @@ class ProcessTest extends 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.
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage The provided cwd does not exist.
*/
public function testInvalidCwd()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('False-positive on Windows/appveyor.');
try {
// Check that it works fine if the CWD exists
$cmd = new Process('echo test', __DIR__);
$cmd->run();
} catch (\Exception $e) {
$this->fail($e);
}
// 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();
}
@@ -118,9 +117,14 @@ class ProcessTest extends TestCase
$p = $this->getProcess(array(self::$phpBin, __DIR__.'/NonStopableProcess.php', 30));
$p->start();
while (false === strpos($p->getOutput(), 'received')) {
while ($p->isRunning() && false === strpos($p->getOutput(), 'received')) {
usleep(1000);
}
if (!$p->isRunning()) {
throw new \LogicException('Process is not running: '.$p->getErrorOutput());
}
$start = microtime(true);
$p->stop(0.1);
@@ -438,7 +442,6 @@ class ProcessTest extends TestCase
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX exit code');
}
$this->skipIfNotEnhancedSigchild();
// such command run in bash return an exitcode 127
$process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
@@ -473,7 +476,6 @@ class ProcessTest extends TestCase
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does have /dev/tty support');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTty(true);
@@ -499,8 +501,6 @@ class ProcessTest extends TestCase
public function testExitCodeTextIsNullWhenExitCodeIsNull()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('');
$this->assertNull($process->getExitCodeText());
}
@@ -521,8 +521,6 @@ class ProcessTest extends TestCase
public function testMustRun()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo');
$this->assertSame($process, $process->mustRun());
@@ -531,8 +529,6 @@ class ProcessTest extends TestCase
public function testSuccessfulMustRunHasCorrectExitCode()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo')->mustRun();
$this->assertEquals(0, $process->getExitCode());
}
@@ -542,16 +538,12 @@ class ProcessTest extends TestCase
*/
public function testMustRunThrowsException()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('exit 1');
$process->mustRun();
}
public function testExitCodeText()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('');
$r = new \ReflectionObject($process);
$p = $r->getProperty('exitcode');
@@ -580,8 +572,6 @@ class ProcessTest extends TestCase
public function testGetExitCodeIsNullOnStart()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcessForCode('usleep(100000);');
$this->assertNull($process->getExitCode());
$process->start();
@@ -592,8 +582,6 @@ class ProcessTest extends TestCase
public function testGetExitCodeIsNullOnWhenStartingAgain()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcessForCode('usleep(100000);');
$process->run();
$this->assertEquals(0, $process->getExitCode());
@@ -605,8 +593,6 @@ class ProcessTest extends TestCase
public function testGetExitCode()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo');
$process->run();
$this->assertSame(0, $process->getExitCode());
@@ -642,8 +628,6 @@ class ProcessTest extends TestCase
public function testIsSuccessful()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo');
$process->run();
$this->assertTrue($process->isSuccessful());
@@ -651,8 +635,6 @@ class ProcessTest extends TestCase
public function testIsSuccessfulOnlyAfterTerminated()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcessForCode('usleep(100000);');
$process->start();
@@ -665,8 +647,6 @@ class ProcessTest extends TestCase
public function testIsNotSuccessful()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcessForCode('throw new \Exception(\'BOUM\');');
$process->run();
$this->assertFalse($process->isSuccessful());
@@ -677,7 +657,6 @@ class ProcessTest extends TestCase
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo');
$process->run();
@@ -689,7 +668,6 @@ class ProcessTest extends TestCase
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('echo foo');
$process->run();
@@ -701,7 +679,6 @@ class ProcessTest extends TestCase
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcessForCode('sleep(32);');
$process->start();
@@ -711,15 +688,18 @@ class ProcessTest extends TestCase
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage The process has been signaled
* @expectedException \Symfony\Component\Process\Exception\ProcessSignaledException
* @expectedExceptionMessage The process has been signaled with signal "9".
*/
public function testProcessThrowsExceptionWhenExternallySignaled()
{
if (!\function_exists('posix_kill')) {
$this->markTestSkipped('Function posix_kill is required.');
}
$this->skipIfNotEnhancedSigchild(false);
if (self::$sigchild) {
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
}
$process = $this->getProcessForCode('sleep(32.1);');
$process->start();
@@ -930,8 +910,6 @@ class ProcessTest extends TestCase
*/
public function testExitCodeIsAvailableAfterSignal()
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess('sleep 4');
$process->start();
$process->signal(SIGKILL);
@@ -1015,10 +993,9 @@ class ProcessTest extends TestCase
}
/**
* @dataProvider provideWrongSignal
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testWrongSignal($signal)
public function testWrongSignal()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('POSIX signals do not work on Windows');
@@ -1027,7 +1004,7 @@ class ProcessTest extends TestCase
$process = $this->getProcessForCode('sleep(38);');
$process->start();
try {
$process->signal($signal);
$process->signal(-4);
$this->fail('A RuntimeException must have been thrown');
} catch (RuntimeException $e) {
$process->stop(0);
@@ -1036,14 +1013,6 @@ class ProcessTest extends TestCase
throw $e;
}
public function provideWrongSignal()
{
return array(
array(-4),
array('Céphalopodes'),
);
}
public function testDisableOutputDisablesTheOutput()
{
$p = $this->getProcess('foo');
@@ -1457,31 +1426,6 @@ class ProcessTest extends TestCase
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'));
@@ -1501,19 +1445,6 @@ class ProcessTest extends TestCase
$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);')));
@@ -1569,21 +1500,6 @@ EOTXT;
$process = new Process($commandline, $cwd, $env, $input, $timeout);
$process->inheritEnvironmentVariables();
if (false !== $enhance = getenv('ENHANCE_SIGCHLD')) {
try {
$process->setEnhanceSigchildCompatibility(false);
$process->getExitCode();
$this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
} catch (RuntimeException $e) {
$this->assertSame('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.', $e->getMessage());
if ($enhance) {
$process->setEnhanceSigchildCompatibility(true);
} else {
self::$notEnhancedSigchild = true;
}
}
}
if (self::$process) {
self::$process->stop(0);
}
@@ -1598,22 +1514,6 @@ EOTXT;
{
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) {
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.');
}
}
}
}
}
class NonStringifiable

View File

@@ -1,53 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\ProcessUtils;
/**
* @group legacy
*/
class ProcessUtilsTest extends TestCase
{
/**
* @dataProvider dataArguments
*/
public function testEscapeArgument($result, $argument)
{
$this->assertSame($result, ProcessUtils::escapeArgument($argument));
}
public function dataArguments()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
return array(
array('"\"php\" \"-v\""', '"php" "-v"'),
array('"foo bar"', 'foo bar'),
array('^%"path"^%', '%path%'),
array('"<|>\\" \\"\'f"', '<|>" "\'f'),
array('""', ''),
array('"with\trailingbs\\\\"', 'with\trailingbs\\'),
);
}
return array(
array("'\"php\" \"-v\"'", '"php" "-v"'),
array("'foo bar'", 'foo bar'),
array("'%path%'", '%path%'),
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
array("''", ''),
array("'with\\trailingbs\\'", 'with\trailingbs\\'),
array("'withNonAsciiAccentLikeéÉèÈàÀöä'", 'withNonAsciiAccentLikeéÉèÈàÀöä'),
);
}
}

View File

@@ -16,7 +16,7 @@
}
],
"require": {
"php": "^5.5.9|>=7.0.8"
"php": "^7.1.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Process\\": "" },
@@ -27,7 +27,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "4.1-dev"
}
}
}