Skip to content

Commit e9cd3c1

Browse files
committed
Fix option duplication handling
1 parent 6d2ffa1 commit e9cd3c1

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/Command.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,18 @@ private function toInternalFormat(array $options): array
339339
$formattedOptions = [];
340340
foreach ($options as $option => $arguments) {
341341
$option = trim((string)$option);
342+
342343
if (strpos($option, '-') !== 0) {
343344
// ['-L', '-v']
344-
$formattedOptions[$arguments] = [null];
345+
$option = (string)$arguments;
346+
$arguments = [null];
345347
} elseif (!is_array($arguments)) {
346348
// ['-L' => null, '-v' => null]
347-
$formattedOptions[$option] = [$arguments];
348-
} else {
349-
// internal format
350-
$formattedOptions[$option] = $arguments;
349+
$arguments = [$arguments];
350+
}
351+
352+
foreach ($arguments as $argument) {
353+
$formattedOptions[$option][] = $argument;
351354
}
352355
}
353356

tests/CommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ public function testBuildDuplicatedOptions(): void
9797
$this->assertSame('curl -v -L -L http://example.com', $command->build());
9898
}
9999

100+
public function testBuildDuplicatedOptionsAddOptions(): void
101+
{
102+
$command = $this->getNewCommand();
103+
$command->addOptions(['-v', '-v']);
104+
$this->assertSame('curl -v -v http://example.com', $command->build());
105+
}
106+
107+
public function testBuildDuplicatedOptionsSetOptions(): void
108+
{
109+
$command = $this->getNewCommand();
110+
$command->setOptions(['-v', '-v']);
111+
$this->assertSame('curl -v -v http://example.com', $command->build());
112+
}
113+
100114
public function testBuildSetTemplate(): void
101115
{
102116
$command = $this->getNewCommand();

0 commit comments

Comments
 (0)