Browse Source

Fix notice error on missing argument

If an argument was defined by had no value a notice error would be
emitted.
Mark Story 7 years ago
parent
commit
5ab3164121
2 changed files with 15 additions and 1 deletions
  1. 1 1
      src/Console/Arguments.php
  2. 14 0
      tests/TestCase/Console/ArgumentsTest.php

+ 1 - 1
src/Console/Arguments.php

@@ -117,7 +117,7 @@ class Arguments
     public function getArgument($name)
     {
         $offset = array_search($name, $this->argNames, true);
-        if ($offset === false) {
+        if ($offset === false || !isset($this->args[$offset])) {
             return null;
         }
 

+ 14 - 0
tests/TestCase/Console/ArgumentsTest.php

@@ -97,6 +97,20 @@ class ArgumentsTest extends TestCase
     }
 
     /**
+     * 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()
      *
      * @return void