[Process] Fix setting empty env vars
This commit is contained in:
parent
6935e5a4aa
commit
03adce239d
@ -326,8 +326,16 @@ class Process implements \IteratorAggregate
|
|||||||
// @see : https://bugs.php.net/69442
|
// @see : https://bugs.php.net/69442
|
||||||
$ptsWorkaround = fopen(__FILE__, 'r');
|
$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, $env, $this->options);
|
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
|
||||||
|
|
||||||
if (!is_resource($this->process)) {
|
if (!is_resource($this->process)) {
|
||||||
throw new RuntimeException('Unable to launch a new process.');
|
throw new RuntimeException('Unable to launch a new process.');
|
||||||
|
@ -1423,14 +1423,14 @@ class ProcessTest extends TestCase
|
|||||||
|
|
||||||
public function testEnvIsInherited()
|
public function testEnvIsInherited()
|
||||||
{
|
{
|
||||||
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ'));
|
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ', 'EMPTY' => ''));
|
||||||
|
|
||||||
putenv('FOO=BAR');
|
putenv('FOO=BAR');
|
||||||
$_ENV['FOO'] = 'BAR';
|
$_ENV['FOO'] = 'BAR';
|
||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
$expected = array('BAR' => 'BAZ', 'FOO' => 'BAR');
|
$expected = array('BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR');
|
||||||
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
|
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
|
||||||
|
|
||||||
$this->assertEquals($expected, $env);
|
$this->assertEquals($expected, $env);
|
||||||
@ -1511,7 +1511,7 @@ Array
|
|||||||
)
|
)
|
||||||
|
|
||||||
EOTXT;
|
EOTXT;
|
||||||
$this->assertSame($expected, $p->getOutput());
|
$this->assertSame($expected, str_replace('Standard input code', '-', $p->getOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideEscapeArgument()
|
public function provideEscapeArgument()
|
||||||
|
Reference in New Issue
Block a user