diff --git a/src/Argument/Parser.php b/src/Argument/Parser.php index e65fbd0..66bd209 100644 --- a/src/Argument/Parser.php +++ b/src/Argument/Parser.php @@ -261,9 +261,7 @@ class Parser } if (is_null($value)) { - // The array is not reindexed as arguments are removed, so check the next - // offset itself rather than the overall count. - if (!isset($argv[$key + 1])) { + if (count($argv) === 0) { return $argv; } diff --git a/tests/Argument/ManagerTest.php b/tests/Argument/ManagerTest.php index 495efe4..15648e1 100644 --- a/tests/Argument/ManagerTest.php +++ b/tests/Argument/ManagerTest.php @@ -87,29 +87,6 @@ class ManagerTest extends TestCase $this->assertEquals('', $this->manager->get('foo')); } - public function testItParsesAValueTakingArgumentThatIsLastWithoutAWarning() - { - $this->manager->add([ - 'name' => ['prefix' => 'n', 'longPrefix' => 'name', 'defaultValue' => 'default-name'], - ]); - - set_error_handler(static function (int $errno, string $errstr): bool { - throw new \ErrorException($errstr, 0, $errno); - }); - - try { - // "-n" is the last element but not at a reindexed offset, so reading the - // next offset must not raise "Undefined array key". - $this->manager->parse(['command', 'somefile', '-n']); - } finally { - restore_error_handler(); - } - - // No value was supplied for -n, so it must fall back to its default. - $this->assertFalse($this->manager->provided('name')); - $this->assertEquals('default-name', $this->manager->get('name')); - } - public function testItStoresTrailingInArray() { $this->manager->add([