/** * @covers Opl_Getopt_Option::setMinOccurences * @covers Opl_Getopt_Option::getMinOccurences */ public function testCountingOccurencesByFoundStatus() { $option = new Opl_Getopt_Option('foo', 'x'); $this->assertEquals(0, $option->getOccurences()); $option->setFound(true); $this->assertEquals(1, $option->getOccurences()); $option->setFound(true); $this->assertEquals(2, $option->getOccurences()); $option->setFound(true); $this->assertEquals(3, $option->getOccurences()); $option->setFound(false); $this->assertEquals(0, $option->getOccurences()); }
/** * 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; }