Skip to content

Commit

Permalink
Fix argument overwrite (#44)
Browse files Browse the repository at this point in the history
* Fix argument overwrite when using setArguments on ProcessBuilder
  • Loading branch information
maschmann authored Feb 5, 2019
1 parent a326c46 commit d7a93fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Ansible/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public function __construct(string $prefix, string $path)
*/
public function setArguments(array $arguments): ProcessBuilderInterface
{
$this->arguments = $arguments;
if (!empty($this->arguments)) {
$this->arguments = array_merge($this->arguments, $arguments);
} else {
$this->arguments = $arguments;
}

return $this;
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Ansible/Process/ProcessBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ public function testCreateInstance()
public function testGetProcess(ProcessBuilderInterface $processBuilder)
{
$process = $processBuilder
->setArguments([])
->setArguments(['more_args'])
->setEnv('SOME', 'value')
->setTimeout(5)
->getProcess();

$this->assertInstanceOf(Process::class, $process);

// verify, all args are kept and merged correctly
$this->assertEquals("'{$this->getGalaxyUri()}' 'more_args'", $process->getCommandLine());
}
}

0 comments on commit d7a93fa

Please sign in to comment.