/** * @covers Opl_Getopt_Option::setValue * @covers Opl_Getopt_Option::getValue */ public function testArgumentValue() { $option = new Opl_Getopt_Option('foo', 'x'); $option->setValue('foo'); $this->assertEquals('foo', $option->getValue()); $option->setValue(42); $this->assertEquals(42, $option->getValue()); }
/** * Does something strange with the option and its argument. * * @internal * @throws Opl_Getopt_Exception * @param Opl_Getopt_Option $option The option * @param string $optionName The option long name for debug purposes. * @param string $optionArgs The option argument */ private function _parseOption(Opl_Getopt_Option $option, $optionName, $optionArgs) { $argument = $option->getArgument(); // Test the arguments if ($argument === null && $optionArgs !== null) { throw new Opl_Getopt_Exception('The option ' . $optionName . ' does not take any arguments.'); } elseif ($argument[0] === Opl_Getopt_Option::REQUIRED && $optionArgs === null) { throw new Opl_Getopt_Exception('The option ' . $optionName . ' requires an argument.'); } // Add the argument. if ($optionArgs !== null) { if ($option->isFound()) { $argVal = $option->getValue(); if (is_array($argVal)) { $argVal[] = $this->_validateArgument($optionName, $optionArgs, $argument[1]); $option->setValue($argVal); } else { $option->setValue(array($argVal, $this->_validateArgument($optionName, $optionArgs, $argument[1]))); } } else { $option->setValue($this->_validateArgument($optionName, $optionArgs, $argument[1])); } } // Now check if it can occur multiple times... if (!($this->_flags & self::ALLOW_INCREMENTING) && $option->isFound()) { throw new Opl_Getopt_Exception($optionName . ' has been used twice.'); } $option->setFound(true); $this->_foundOpts[] = $option; }