feature#8191 [Process] Added ProcessBuilder::setEnvironmentVariables (lyrixx)
This PR was merged into the master branch.
Discussion
----------
[Process] Added ProcessBuilder::setEnvironmentVariables
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
b46ebf7
[Process] Added ProcessBuilder::addEnvironmentVariables
This commit is contained in:
commit
500ddf3494
@ -108,6 +108,13 @@ class ProcessBuilder
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addEnvironmentVariables(array $variables)
|
||||||
|
{
|
||||||
|
$this->env = array_replace($this->env, $variables);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setInput($stdin)
|
public function setInput($stdin)
|
||||||
{
|
{
|
||||||
$this->stdin = $stdin;
|
$this->stdin = $stdin;
|
||||||
|
@ -30,6 +30,23 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foo', $env['MY_VAR_1']);
|
$this->assertEquals('foo', $env['MY_VAR_1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
public function testProcessShouldInheritAndOverrideEnvironmentVars()
|
public function testProcessShouldInheritAndOverrideEnvironmentVars()
|
||||||
{
|
{
|
||||||
$_ENV['MY_VAR_1'] = 'foo';
|
$_ENV['MY_VAR_1'] = 'foo';
|
||||||
|
Reference in New Issue
Block a user