merged branch asm89/enhance-processbuilder (PR #5853)

This PR was squashed before being merged into the master branch (closes #5853).

Commits
-------

63b0059 [Process] Add ability to reset arguments on ProcessBuilder

Discussion
----------

[Process] Add ability to reset arguments on ProcessBuilder

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

This PR adds the ability to "reset" the arguments set on a `ProcessBuilder`. This allows the builder to be re-used without having to set things like custom environment variables, current working directory etc again.
This commit is contained in:
Fabien Potencier 2012-12-06 14:11:58 +01:00
commit 8968bd0e03
3 changed files with 23 additions and 0 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
2.2.0
-----
* added ProcessBuilder::setArguments() to reset the arguments on a builder
* added a way to retrieve the standard and error output incrementally
* added Process:restart()

View File

@ -56,6 +56,18 @@ class ProcessBuilder
return $this;
}
/**
* @param array $arguments
*
* @return ProcessBuilder
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;

View File

@ -105,4 +105,14 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
$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());
}
}