/** * Test get value. * * @param array $inputs The input option. * * @dataProvider optionProvider * * @return void * * @since 1.0 */ public function testGetValue($inputs) { foreach ($inputs as $key => $vals) { $this->instance->getInput()->set($key, 1); foreach ($vals as $val) { $this->assertEquals(1, $this->instance->getValue($val)); } } // Filter $this->instance->getInput()->set('y', 'flower sakura'); $this->assertEquals('flower sakura', $this->instance->getValue('y'), 'Default input filter should string.'); }
/** * Add a option object to this command. * * @param mixed $option The option name. Can be a string, an array or an object. * If we use array, the first element will be option name, others will be alias. * @param mixed $default The default value when we get a non-exists option. * @param string $description The option description. * @param bool $global If true, this option will be a global option that sub commends will extends it. * * @return AbstractCommand Return this object to support chaining. * * @since 1.0 */ public function addOption($option, $default = null, $description = null, $global = false) { if (!$option instanceof Option) { $option = new Option($option, $default, $description, $global); } $option->setInput($this->input); $name = $option->getName(); $global = $option->isGlobal(); if ($global) { $this->globalOptions[$name] = $option; // Global option should not equal to private option unset($this->options[$name]); // We should pass global option to all children. foreach ($this->children as $child) { $child->addOption($option); } } else { $this->options[$name] = $option; // Global option should not equal to private option unset($this->globalOptions[$name]); } return $this; }