Skip to content

Commit d7a93fa

Browse files
authored
Fix argument overwrite (#44)
* Fix argument overwrite when using setArguments on ProcessBuilder
1 parent a326c46 commit d7a93fa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Ansible/Process/ProcessBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public function __construct(string $prefix, string $path)
6363
*/
6464
public function setArguments(array $arguments): ProcessBuilderInterface
6565
{
66-
$this->arguments = $arguments;
66+
if (!empty($this->arguments)) {
67+
$this->arguments = array_merge($this->arguments, $arguments);
68+
} else {
69+
$this->arguments = $arguments;
70+
}
6771

6872
return $this;
6973
}

Tests/Ansible/Process/ProcessBuilderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ public function testCreateInstance()
3737
public function testGetProcess(ProcessBuilderInterface $processBuilder)
3838
{
3939
$process = $processBuilder
40-
->setArguments([])
40+
->setArguments(['more_args'])
4141
->setEnv('SOME', 'value')
4242
->setTimeout(5)
4343
->getProcess();
4444

4545
$this->assertInstanceOf(Process::class, $process);
46+
47+
// verify, all args are kept and merged correctly
48+
$this->assertEquals("'{$this->getGalaxyUri()}' 'more_args'", $process->getCommandLine());
4649
}
4750
}
4851

0 commit comments

Comments
 (0)