updated packages

This commit is contained in:
2019-05-18 09:06:43 +00:00
parent 901d16349e
commit e9487fa58a
2025 changed files with 30366 additions and 49653 deletions

View File

@@ -21,9 +21,9 @@ CHANGELOG
-----
* environment variables will always be inherited
* added a second `array $env = array()` argument to the `start()`, `run()`,
* added a second `array $env = []` 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
* added a second `array $env = []` argument to the `start()` method of the
`PhpProcess` class
* the `ProcessUtils::escapeArgument()` method has been removed
* the `areEnvironmentVariablesInherited()`, `getOptions()`, and `setOptions()`

View File

@@ -19,7 +19,7 @@ namespace Symfony\Component\Process;
*/
class ExecutableFinder
{
private $suffixes = array('.exe', '.bat', '.cmd', '.com');
private $suffixes = ['.exe', '.bat', '.cmd', '.com'];
/**
* Replaces default suffixes of executable.
@@ -48,11 +48,11 @@ class ExecutableFinder
*
* @return string|null The executable path or default value
*/
public function find($name, $default = null, array $extraDirs = array())
public function find($name, $default = null, array $extraDirs = [])
{
if (ini_get('open_basedir')) {
$searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
$dirs = array();
$searchPath = array_merge(explode(PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs);
$dirs = [];
foreach ($searchPath as $path) {
// Silencing against https://bugs.php.net/69240
if (@is_dir($path)) {
@@ -70,7 +70,7 @@ class ExecutableFinder
);
}
$suffixes = array('');
$suffixes = [''];
if ('\\' === \DIRECTORY_SEPARATOR) {
$pathExt = getenv('PATHEXT');
$suffixes = array_merge($pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes);

View File

@@ -22,7 +22,7 @@ class InputStream implements \IteratorAggregate
{
/** @var callable|null */
private $onEmpty = null;
private $input = array();
private $input = [];
private $open = true;
/**

View File

@@ -54,7 +54,7 @@ class PhpExecutableFinder
$args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
// PHP_BINARY return the current sapi executable
if (PHP_BINARY && \in_array(\PHP_SAPI, array('cli', 'cli-server', 'phpdbg'), true)) {
if (PHP_BINARY && \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true)) {
return PHP_BINARY.$args;
}
@@ -76,7 +76,7 @@ class PhpExecutableFinder
return $php;
}
$dirs = array(PHP_BINDIR);
$dirs = [PHP_BINDIR];
if ('\\' === \DIRECTORY_SEPARATOR) {
$dirs[] = 'C:\xampp\php\\';
}
@@ -91,7 +91,7 @@ class PhpExecutableFinder
*/
public function findArguments()
{
$arguments = array();
$arguments = [];
if ('phpdbg' === \PHP_SAPI) {
$arguments[] = '-qrr';
}

View File

@@ -33,11 +33,10 @@ class PhpProcess extends Process
*/
public function __construct(string $script, string $cwd = null, array $env = null, int $timeout = 60, array $php = null)
{
$executableFinder = new PhpExecutableFinder();
if (false === $php = $php ?? $executableFinder->find(false)) {
$php = null;
} else {
$php = array_merge(array($php), $executableFinder->findArguments());
if (null === $php) {
$executableFinder = new PhpExecutableFinder();
$php = $executableFinder->find(false);
$php = false === $php ? null : array_merge([$php], $executableFinder->findArguments());
}
if ('phpdbg' === \PHP_SAPI) {
$file = tempnam(sys_get_temp_dir(), 'dbg');
@@ -65,7 +64,7 @@ class PhpProcess extends Process
/**
* {@inheritdoc}
*/
public function start(callable $callback = null, array $env = array())
public function start(callable $callback = null, array $env = [])
{
if (null === $this->getCommandLine()) {
throw new RuntimeException('Unable to find the PHP executable.');

View File

@@ -20,7 +20,7 @@ use Symfony\Component\Process\Exception\InvalidArgumentException;
*/
abstract class AbstractPipes implements PipesInterface
{
public $pipes = array();
public $pipes = [];
private $inputBuffer = '';
private $input;
@@ -49,7 +49,7 @@ abstract class AbstractPipes implements PipesInterface
foreach ($this->pipes as $pipe) {
fclose($pipe);
}
$this->pipes = array();
$this->pipes = [];
}
/**
@@ -117,8 +117,8 @@ abstract class AbstractPipes implements PipesInterface
}
}
$r = $e = array();
$w = array($this->pipes[0]);
$r = $e = [];
$w = [$this->pipes[0]];
// let's have a look if something changed in streams
if (false === @stream_select($r, $w, $e, 0, 0)) {
@@ -130,7 +130,7 @@ abstract class AbstractPipes implements PipesInterface
$written = fwrite($stdin, $this->inputBuffer);
$this->inputBuffer = substr($this->inputBuffer, $written);
if (isset($this->inputBuffer[0])) {
return array($this->pipes[0]);
return [$this->pipes[0]];
}
}
@@ -145,7 +145,7 @@ abstract class AbstractPipes implements PipesInterface
if (isset($data[0])) {
$this->inputBuffer = $data;
return array($this->pipes[0]);
return [$this->pipes[0]];
}
}
if (feof($input)) {
@@ -164,7 +164,7 @@ abstract class AbstractPipes implements PipesInterface
fclose($this->pipes[0]);
unset($this->pipes[0]);
} elseif (!$w) {
return array($this->pipes[0]);
return [$this->pipes[0]];
}
}

View File

@@ -48,34 +48,34 @@ class UnixPipes extends AbstractPipes
if (!$this->haveReadSupport) {
$nullstream = fopen('/dev/null', 'c');
return array(
array('pipe', 'r'),
return [
['pipe', 'r'],
$nullstream,
$nullstream,
);
];
}
if ($this->ttyMode) {
return array(
array('file', '/dev/tty', 'r'),
array('file', '/dev/tty', 'w'),
array('file', '/dev/tty', 'w'),
);
return [
['file', '/dev/tty', 'r'],
['file', '/dev/tty', 'w'],
['file', '/dev/tty', 'w'],
];
}
if ($this->ptyMode && Process::isPtySupported()) {
return array(
array('pty'),
array('pty'),
array('pty'),
);
return [
['pty'],
['pty'],
['pty'],
];
}
return array(
array('pipe', 'r'),
array('pipe', 'w'), // stdout
array('pipe', 'w'), // stderr
);
return [
['pipe', 'r'],
['pipe', 'w'], // stdout
['pipe', 'w'], // stderr
];
}
/**
@@ -83,7 +83,7 @@ class UnixPipes extends AbstractPipes
*/
public function getFiles()
{
return array();
return [];
}
/**
@@ -94,18 +94,18 @@ class UnixPipes extends AbstractPipes
$this->unblock();
$w = $this->write();
$read = $e = array();
$read = $e = [];
$r = $this->pipes;
unset($r[0]);
// let's have a look if something changed in streams
set_error_handler(array($this, 'handleError'));
set_error_handler([$this, 'handleError']);
if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
restore_error_handler();
// 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()) {
$this->pipes = array();
$this->pipes = [];
}
return $read;

View File

@@ -26,13 +26,13 @@ use Symfony\Component\Process\Process;
*/
class WindowsPipes extends AbstractPipes
{
private $files = array();
private $fileHandles = array();
private $lockHandles = array();
private $readBytes = array(
private $files = [];
private $fileHandles = [];
private $lockHandles = [];
private $readBytes = [
Process::STDOUT => 0,
Process::STDERR => 0,
);
];
private $haveReadSupport;
public function __construct($input, bool $haveReadSupport)
@@ -44,10 +44,10 @@ class WindowsPipes extends AbstractPipes
// Workaround for this problem is to use temporary files instead of pipes on Windows platform.
//
// @see https://bugs.php.net/bug.php?id=51800
$pipes = array(
$pipes = [
Process::STDOUT => Process::OUT,
Process::STDERR => Process::ERR,
);
];
$tmpDir = sys_get_temp_dir();
$lastError = 'unknown reason';
set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
@@ -98,21 +98,21 @@ class WindowsPipes extends AbstractPipes
if (!$this->haveReadSupport) {
$nullstream = fopen('NUL', 'c');
return array(
array('pipe', 'r'),
return [
['pipe', 'r'],
$nullstream,
$nullstream,
);
];
}
// We're not using pipe on Windows platform as it hangs (https://bugs.php.net/bug.php?id=51800)
// We're not using file handles as it can produce corrupted output https://bugs.php.net/bug.php?id=65650
// So we redirect output within the commandline and pass the nul device to the process
return array(
array('pipe', 'r'),
array('file', 'NUL', 'w'),
array('file', 'NUL', 'w'),
);
return [
['pipe', 'r'],
['file', 'NUL', 'w'],
['file', 'NUL', 'w'],
];
}
/**
@@ -130,7 +130,7 @@ class WindowsPipes extends AbstractPipes
{
$this->unblock();
$w = $this->write();
$read = $r = $e = array();
$read = $r = $e = [];
if ($blocking) {
if ($w) {
@@ -186,6 +186,6 @@ class WindowsPipes extends AbstractPipes
flock($this->lockHandles[$type], LOCK_UN);
fclose($this->lockHandles[$type]);
}
$this->fileHandles = $this->lockHandles = array();
$this->fileHandles = $this->lockHandles = [];
}
}

View File

@@ -60,7 +60,7 @@ class Process implements \IteratorAggregate
private $timeout;
private $idleTimeout;
private $exitcode;
private $fallbackStatus = array();
private $fallbackStatus = [];
private $processInformation;
private $outputDisabled = false;
private $stdout;
@@ -85,7 +85,7 @@ class Process implements \IteratorAggregate
*
* User-defined errors must use exit codes in the 64-113 range.
*/
public static $exitCodes = array(
public static $exitCodes = [
0 => 'OK',
1 => 'General error',
2 => 'Misuse of shell builtins',
@@ -126,7 +126,7 @@ class Process implements \IteratorAggregate
157 => 'Pollable event',
// 158 - not defined
159 => 'Bad syscall',
);
];
/**
* @param array $command The command to run and its arguments listed as separate entries
@@ -190,7 +190,7 @@ class Process implements \IteratorAggregate
*/
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
$process = new static(array(), $cwd, $env, $input, $timeout);
$process = new static([], $cwd, $env, $input, $timeout);
$process->commandline = $command;
return $process;
@@ -228,7 +228,7 @@ class Process implements \IteratorAggregate
*
* @final
*/
public function run(callable $callback = null, array $env = array()): int
public function run(callable $callback = null, array $env = []): int
{
$this->start($callback, $env);
@@ -250,7 +250,7 @@ class Process implements \IteratorAggregate
*
* @final
*/
public function mustRun(callable $callback = null, array $env = array())
public function mustRun(callable $callback = null, array $env = [])
{
if (0 !== $this->run($callback, $env)) {
throw new ProcessFailedException($this);
@@ -279,7 +279,7 @@ 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 = [])
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
@@ -292,7 +292,7 @@ class Process implements \IteratorAggregate
$descriptors = $this->getDescriptors();
if (\is_array($commandline = $this->commandline)) {
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
$commandline = implode(' ', array_map([$this, 'escapeArgument'], $commandline));
if ('\\' !== \DIRECTORY_SEPARATOR) {
// exec is mandatory to deal with sending a signal to the process
@@ -305,14 +305,14 @@ class Process implements \IteratorAggregate
}
$env += $this->getDefaultEnv();
$options = array('suppress_errors' => true);
$options = ['suppress_errors' => true];
if ('\\' === \DIRECTORY_SEPARATOR) {
$options['bypass_shell'] = true;
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
} 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');
$descriptors[3] = ['pipe', 'w'];
// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
$commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
@@ -323,7 +323,7 @@ class Process implements \IteratorAggregate
$ptsWorkaround = fopen(__FILE__, 'r');
}
$envPairs = array();
$envPairs = [];
foreach ($env as $k => $v) {
if (false !== $v) {
$envPairs[] = $k.'='.$v;
@@ -371,7 +371,7 @@ class Process implements \IteratorAggregate
*
* @final
*/
public function restart(callable $callback = null, array $env = array())
public function restart(callable $callback = null, array $env = [])
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
@@ -961,7 +961,7 @@ class Process implements \IteratorAggregate
*/
public function getCommandLine()
{
return \is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
return \is_array($this->commandline) ? implode(' ', array_map([$this, 'escapeArgument'], $this->commandline)) : $this->commandline;
}
/**
@@ -1251,7 +1251,7 @@ class Process implements \IteratorAggregate
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);
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
}
return $isTtySupported;
@@ -1274,7 +1274,7 @@ class Process implements \IteratorAggregate
return $result = false;
}
return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
return $result = (bool) @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
}
/**
@@ -1472,7 +1472,7 @@ class Process implements \IteratorAggregate
$this->starttime = null;
$this->callback = null;
$this->exitcode = null;
$this->fallbackStatus = array();
$this->fallbackStatus = [];
$this->processInformation = null;
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+b');
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+b');
@@ -1519,7 +1519,7 @@ class Process implements \IteratorAggregate
$ok = @proc_terminate($this->process, $signal);
} elseif (\function_exists('posix_kill')) {
$ok = @posix_kill($pid, $signal);
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), array(2 => array('pipe', 'w')), $pipes)) {
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
$ok = false === fgets($pipes[2]);
}
if (!$ok) {
@@ -1543,7 +1543,7 @@ class Process implements \IteratorAggregate
{
$uid = uniqid('', true);
$varCount = 0;
$varCache = array();
$varCache = [];
$cmd = preg_replace_callback(
'/"(?:(
[^"%!^]*+
@@ -1566,7 +1566,7 @@ class Process implements \IteratorAggregate
return '"'.$value.'"';
}
$value = str_replace(array('!LF!', '"^!"', '"^%"', '"^^"', '""'), array("\n", '!', '%', '^', '"'), $value);
$value = str_replace(['!LF!', '"^!"', '"^%"', '"^^"', '""'], ["\n", '!', '%', '^', '"'], $value);
$value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"';
$var = $uid.++$varCount;
@@ -1628,12 +1628,12 @@ class Process implements \IteratorAggregate
}
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"';
}
private function getDefaultEnv()
{
$env = array();
$env = [];
foreach ($_SERVER as $k => $v) {
if (\is_string($v) && false !== $v = getenv($k)) {

View File

@@ -88,7 +88,7 @@ class ExecutableFinderTest extends TestCase
$this->setPath('');
$extraDirs = array(\dirname(PHP_BINARY));
$extraDirs = [\dirname(PHP_BINARY)];
$finder = new ExecutableFinder();
$result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);

View File

@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
$outputs = array(
$outputs = [
'First iteration output',
'Second iteration output',
'One more iteration output',
'This took more time',
);
];
$iterationTime = 10000;

View File

@@ -41,9 +41,9 @@ class PhpExecutableFinderTest extends TestCase
$f = new PhpExecutableFinder();
if ('phpdbg' === \PHP_SAPI) {
$this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
$this->assertEquals($f->findArguments(), ['-qrr'], '::findArguments() returns phpdbg arguments');
} else {
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
$this->assertEquals($f->findArguments(), [], '::findArguments() returns no arguments');
}
}
}

View File

@@ -12,6 +12,7 @@
namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\PhpProcess;
class PhpProcessTest extends TestCase
@@ -45,4 +46,18 @@ PHP
$this->assertSame(PHP_VERSION.\PHP_SAPI, $process->getOutput());
}
public function testPassingPhpExplicitly()
{
$finder = new PhpExecutableFinder();
$php = array_merge([$finder->find(false)], $finder->findArguments());
$expected = 'hello world!';
$script = <<<PHP
<?php echo '$expected';
PHP;
$process = new PhpProcess($script, null, null, 60, $php);
$process->run();
$this->assertEquals($expected, $process->getOutput());
}
}

View File

@@ -14,8 +14,8 @@ define('ERR_TIMEOUT', 2);
define('ERR_READ_FAILED', 3);
define('ERR_WRITE_FAILED', 4);
$read = array(STDIN);
$write = array(STDOUT, STDERR);
$read = [STDIN];
$write = [STDOUT, STDERR];
stream_set_blocking(STDIN, 0);
stream_set_blocking(STDOUT, 0);
@@ -42,7 +42,7 @@ while ($read || $write) {
$out = (string) substr($out, $written);
}
if (null === $read && '' === $out) {
$write = array_diff($write, array(STDOUT));
$write = array_diff($write, [STDOUT]);
}
if (in_array(STDERR, $w) && strlen($err) > 0) {
@@ -53,7 +53,7 @@ while ($read || $write) {
$err = (string) substr($err, $written);
}
if (null === $read && '' === $err) {
$write = array_diff($write, array(STDERR));
$write = array_diff($write, [STDERR]);
}
if ($r) {

View File

@@ -24,7 +24,7 @@ class ProcessFailedExceptionTest extends TestCase
*/
public function testProcessFailedExceptionThrowsException()
{
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful'))->setConstructorArgs(array(array('php')))->getMock();
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful'])->setConstructorArgs([['php']])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(true));
@@ -52,7 +52,7 @@ class ProcessFailedExceptionTest extends TestCase
$errorOutput = 'FATAL: Unexpected error';
$workingDirectory = getcwd();
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'))->setConstructorArgs(array(array($cmd)))->getMock();
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));
@@ -100,7 +100,7 @@ class ProcessFailedExceptionTest extends TestCase
$exitText = 'General error';
$workingDirectory = getcwd();
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'))->setConstructorArgs(array(array($cmd)))->getMock();
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));

View File

@@ -55,13 +55,13 @@ class ProcessTest extends TestCase
{
try {
// Check that it works fine if the CWD exists
$cmd = new Process(array('echo', 'test'), __DIR__);
$cmd = new Process(['echo', 'test'], __DIR__);
$cmd->run();
} catch (\Exception $e) {
$this->fail($e);
}
$cmd = new Process(array('echo', 'test'), __DIR__.'/notfound/');
$cmd = new Process(['echo', 'test'], __DIR__.'/notfound/');
$cmd->run();
}
@@ -114,7 +114,7 @@ class ProcessTest extends TestCase
*/
public function testStopWithTimeoutIsActuallyWorking()
{
$p = $this->getProcess(array(self::$phpBin, __DIR__.'/NonStopableProcess.php', 30));
$p = $this->getProcess([self::$phpBin, __DIR__.'/NonStopableProcess.php', 30]);
$p->start();
while ($p->isRunning() && false === strpos($p->getOutput(), 'received')) {
@@ -135,7 +135,11 @@ class ProcessTest extends TestCase
public function testWaitUntilSpecificOutput()
{
$p = $this->getProcess(array(self::$phpBin, __DIR__.'/KillableProcessWithOutput.php'));
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestIncomplete('This test is too transient on Windows, help wanted to improve it');
}
$p = $this->getProcess([self::$phpBin, __DIR__.'/KillableProcessWithOutput.php']);
$p->start();
$start = microtime(true);
@@ -304,10 +308,10 @@ class ProcessTest extends TestCase
public function provideInvalidInputValues()
{
return array(
array(array()),
array(new NonStringifiable()),
);
return [
[[]],
[new NonStringifiable()],
];
}
/**
@@ -322,25 +326,25 @@ class ProcessTest extends TestCase
public function provideInputValues()
{
return array(
array(null, null),
array('24.5', 24.5),
array('input data', 'input data'),
);
return [
[null, null],
['24.5', 24.5],
['input data', 'input data'],
];
}
public function chainedCommandsOutputProvider()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
return array(
array("2 \r\n2\r\n", '&&', '2'),
);
return [
["2 \r\n2\r\n", '&&', '2'],
];
}
return array(
array("1\n1\n", ';', '1'),
array("2\n2\n", '&&', '2'),
);
return [
["1\n1\n", ';', '1'],
["2\n2\n", '&&', '2'],
];
}
/**
@@ -409,7 +413,7 @@ class ProcessTest extends TestCase
$p->start();
foreach (array('foo', 'bar') as $s) {
foreach (['foo', 'bar'] as $s) {
while (false === strpos($p->$getOutput(), $s)) {
usleep(1000);
}
@@ -425,10 +429,10 @@ class ProcessTest extends TestCase
public function provideIncrementalOutput()
{
return array(
array('getOutput', 'getIncrementalOutput', 'php://stdout'),
array('getErrorOutput', 'getIncrementalErrorOutput', 'php://stderr'),
);
return [
['getOutput', 'getIncrementalOutput', 'php://stdout'],
['getErrorOutput', 'getIncrementalErrorOutput', 'php://stderr'],
];
}
public function testGetOutput()
@@ -911,7 +915,7 @@ class ProcessTest extends TestCase
*/
public function testSignal()
{
$process = $this->getProcess(array(self::$phpBin, __DIR__.'/SignalListener.php'));
$process = $this->getProcess([self::$phpBin, __DIR__.'/SignalListener.php']);
$process->start();
while (false === strpos($process->getOutput(), 'Caught')) {
@@ -971,13 +975,13 @@ class ProcessTest extends TestCase
public function provideMethodsThatNeedARunningProcess()
{
return array(
array('getOutput'),
array('getIncrementalOutput'),
array('getErrorOutput'),
array('getIncrementalErrorOutput'),
array('wait'),
);
return [
['getOutput'],
['getIncrementalOutput'],
['getErrorOutput'],
['getIncrementalErrorOutput'],
['wait'],
];
}
/**
@@ -1002,12 +1006,12 @@ class ProcessTest extends TestCase
public function provideMethodsThatNeedATerminatedProcess()
{
return array(
array('hasBeenSignaled'),
array('getTermSignal'),
array('hasBeenStopped'),
array('getStopSignal'),
);
return [
['hasBeenSignaled'],
['getTermSignal'],
['hasBeenStopped'],
['getStopSignal'],
];
}
/**
@@ -1118,12 +1122,12 @@ class ProcessTest extends TestCase
public function provideOutputFetchingMethods()
{
return array(
array('getOutput'),
array('getIncrementalOutput'),
array('getErrorOutput'),
array('getIncrementalErrorOutput'),
);
return [
['getOutput'],
['getIncrementalOutput'],
['getErrorOutput'],
['getIncrementalErrorOutput'],
];
}
public function testStopTerminatesProcessCleanly()
@@ -1155,32 +1159,32 @@ class ProcessTest extends TestCase
public function responsesCodeProvider()
{
return array(
return [
//expected output / getter / code to execute
//array(1,'getExitCode','exit(1);'),
//array(true,'isSuccessful','exit();'),
array('output', 'getOutput', 'echo \'output\';'),
);
// [1,'getExitCode','exit(1);'],
// [true,'isSuccessful','exit();'],
['output', 'getOutput', 'echo \'output\';'],
];
}
public function pipesCodeProvider()
{
$variations = array(
$variations = [
'fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);',
'include \''.__DIR__.'/PipeStdinInStdoutStdErrStreamSelect.php\';',
);
];
if ('\\' === \DIRECTORY_SEPARATOR) {
// Avoid XL buffers on Windows because of https://bugs.php.net/bug.php?id=65650
$sizes = array(1, 2, 4, 8);
$sizes = [1, 2, 4, 8];
} else {
$sizes = array(1, 16, 64, 1024, 4096);
$sizes = [1, 16, 64, 1024, 4096];
}
$codes = array();
$codes = [];
foreach ($sizes as $size) {
foreach ($variations as $code) {
$codes[] = array($code, $size);
$codes[] = [$code, $size];
}
}
@@ -1208,10 +1212,10 @@ class ProcessTest extends TestCase
public function provideVariousIncrementals()
{
return array(
array('php://stdout', 'getIncrementalOutput'),
array('php://stderr', 'getIncrementalErrorOutput'),
);
return [
['php://stdout', 'getIncrementalOutput'],
['php://stderr', 'getIncrementalErrorOutput'],
];
}
public function testIteratorInput()
@@ -1316,32 +1320,32 @@ class ProcessTest extends TestCase
$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();
$output = [];
foreach ($process as $type => $data) {
$output[] = array($type, $data);
$output[] = [$type, $data];
break;
}
$expectedOutput = array(
array($process::OUT, '123'),
);
$expectedOutput = [
[$process::OUT, '123'],
];
$this->assertSame($expectedOutput, $output);
$input->write(345);
foreach ($process as $type => $data) {
$output[] = array($type, $data);
$output[] = [$type, $data];
}
$this->assertSame('', $process->getOutput());
$this->assertFalse($process->isRunning());
$expectedOutput = array(
array($process::OUT, '123'),
array($process::ERR, '234'),
array($process::OUT, '345'),
array($process::ERR, '456'),
);
$expectedOutput = [
[$process::OUT, '123'],
[$process::ERR, '234'],
[$process::OUT, '345'],
[$process::ERR, '456'],
];
$this->assertSame($expectedOutput, $output);
}
@@ -1352,32 +1356,32 @@ class ProcessTest extends TestCase
$process = $this->getProcessForCode('fwrite(STDOUT, fread(STDIN, 3));');
$process->setInput($input);
$process->start();
$output = array();
$output = [];
foreach ($process->getIterator($process::ITER_NON_BLOCKING | $process::ITER_KEEP_OUTPUT) as $type => $data) {
$output[] = array($type, $data);
$output[] = [$type, $data];
break;
}
$expectedOutput = array(
array($process::OUT, ''),
);
$expectedOutput = [
[$process::OUT, ''],
];
$this->assertSame($expectedOutput, $output);
$input->write(123);
foreach ($process->getIterator($process::ITER_NON_BLOCKING | $process::ITER_KEEP_OUTPUT) as $type => $data) {
if ('' !== $data) {
$output[] = array($type, $data);
$output[] = [$type, $data];
}
}
$this->assertSame('123', $process->getOutput());
$this->assertFalse($process->isRunning());
$expectedOutput = array(
array($process::OUT, ''),
array($process::OUT, '123'),
);
$expectedOutput = [
[$process::OUT, ''],
[$process::OUT, '123'],
];
$this->assertSame($expectedOutput, $output);
}
@@ -1399,7 +1403,7 @@ class ProcessTest extends TestCase
public function testSetBadEnv()
{
$process = $this->getProcess('echo hello');
$process->setEnv(array('bad%%' => '123'));
$process->setEnv(['bad%%' => '123']);
$process->inheritEnvironmentVariables(true);
$process->run();
@@ -1413,7 +1417,7 @@ class ProcessTest extends TestCase
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->setEnv(['existing_var' => 'bar', 'new_test_var' => 'foo']);
$process->inheritEnvironmentVariables();
$process->run();
@@ -1428,14 +1432,14 @@ class ProcessTest extends TestCase
public function testEnvIsInherited()
{
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ', 'EMPTY' => ''));
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, ['BAR' => 'BAZ', 'EMPTY' => '']);
putenv('FOO=BAR');
$_ENV['FOO'] = 'BAR';
$process->run();
$expected = array('BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR');
$expected = ['BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR'];
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
$this->assertEquals($expected, $env);
@@ -1446,7 +1450,7 @@ class ProcessTest extends TestCase
public function testGetCommandLine()
{
$p = new Process(array('/usr/bin/php'));
$p = new Process(['/usr/bin/php']);
$expected = '\\' === \DIRECTORY_SEPARATOR ? '"/usr/bin/php"' : "'/usr/bin/php'";
$this->assertSame($expected, $p->getCommandLine());
@@ -1457,7 +1461,7 @@ class ProcessTest extends TestCase
*/
public function testEscapeArgument($arg)
{
$p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg));
$p = new Process([self::$phpBin, '-r', 'echo $argv[1];', $arg]);
$p->run();
$this->assertSame((string) $arg, $p->getOutput());
@@ -1483,24 +1487,24 @@ EOTXT;
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('éÉèÈàÀöä');
yield array(null);
yield array(1);
yield array(1.1);
yield ['a"b%c%'];
yield ['a"b^c^'];
yield ["a\nb'c"];
yield ['a^b c!'];
yield ["a!b\tc"];
yield ['a\\\\"\\"'];
yield ['éÉèÈàÀöä'];
yield [null];
yield [1];
yield [1.1];
}
public function testEnvArgument()
{
$env = array('FOO' => 'Foo', 'BAR' => 'Bar');
$env = ['FOO' => 'Foo', 'BAR' => 'Bar'];
$cmd = '\\' === \DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ';
$p = Process::fromShellCommandline($cmd, null, $env);
$p->run(null, array('BAR' => 'baR', 'BAZ' => 'baZ'));
$p->run(null, ['BAR' => 'baR', 'BAZ' => 'baZ']);
$this->assertSame('Foo baR baZ', rtrim($p->getOutput()));
$this->assertSame($env, $p->getEnv());
@@ -1524,7 +1528,7 @@ EOTXT;
private function getProcessForCode(string $code, string $cwd = null, array $env = null, $input = null, ?int $timeout = 60): Process
{
return $this->getProcess(array(self::$phpBin, '-r', $code), $cwd, $env, $input, $timeout);
return $this->getProcess([self::$phpBin, '-r', $code], $cwd, $env, $input, $timeout);
}
}