Skip to content

Commit

Permalink
Fix #35 - do not load secondary arguments into value of primary
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed May 31, 2019
1 parent b659eb1 commit 5bbb67b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Argument/ArgumentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ protected function buildArgumentList(array $arguments):void {
);
}
else {
$skipNextArgument = true;
$name = $arg;
$value = $arguments[$i + 1] ?? null;

$nextArgument = $arguments[$i + 1] ?? null;

if($nextArgument
&& strpos($nextArgument, "-") !== 0) {
$value = $arguments[$i + 1];
$skipNextArgument = true;
}
else {
$value = null;
}
}

if ($arg[1] === "-") {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/Argument/ArgumentListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,31 @@ public function testGetValueParameterWithShortOption(string...$args) {
self::assertEquals($args[2], $value);
}

public function testGetValueForParameterForMultiple() {
$argumentList = new ArgumentList(
"test-script",
"test-command",
"--one",
"--two",
"--three",
"--four"
);

$param1 = self::createMock(Parameter::class);
$param1->method("getLongOption")->willReturn("one");
$param2 = self::createMock(Parameter::class);
$param2->method("getLongOption")->willReturn("two");
$param3 = self::createMock(Parameter::class);
$param3->method("getLongOption")->willReturn("three");
$param4 = self::createMock(Parameter::class);
$param4->method("getLongOption")->willReturn("four");

self::assertTrue($argumentList->contains($param1));
self::assertTrue($argumentList->contains($param2));
self::assertTrue($argumentList->contains($param3));
self::assertTrue($argumentList->contains($param4));
}

public function data_randomNamedArgs():array {
$dataSet = [];

Expand Down

0 comments on commit 5bbb67b

Please sign in to comment.