Skip to content

Commit

Permalink
Fix notice error on missing argument
Browse files Browse the repository at this point in the history
If an argument was defined by had no value a notice error would be
emitted.
  • Loading branch information
markstory committed Dec 17, 2018
1 parent 540c353 commit 5ab3164
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Console/Arguments.php
Expand Up @@ -117,7 +117,7 @@ public function hasArgument($name)
public function getArgument($name)
{
$offset = array_search($name, $this->argNames, true);
if ($offset === false) {
if ($offset === false || !isset($this->args[$offset])) {
return null;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Console/ArgumentsTest.php
Expand Up @@ -96,6 +96,20 @@ public function testGetArgument()
$this->assertNull($args->getArgument('hair'));
}

/**
* get arguments missing value
*
* @return void
*/
public function testGetArgumentMissing()
{
$values = [];
$names = ['size', 'color'];
$args = new Arguments($values, [], $names);
$this->assertNull($args->getArgument('size'));
$this->assertNull($args->getArgument('color'));
}

/**
* test getOptions()
*
Expand Down

0 comments on commit 5ab3164

Please sign in to comment.