$t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode'); $t->is($option->isParameterOptional(), true, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode'); try { $option = new sfCommandOption('foo', 'f', 'ANOTHER_ONE'); $t->fail('__construct() throws an sfCommandException if the mode is not valid'); } catch (sfCommandException $e) { $t->pass('__construct() throws an sfCommandException if the mode is not valid'); } // ->isArray() $t->diag('->isArray()'); $option = new sfCommandOption('foo', null, sfCommandOption::IS_ARRAY); $t->ok($option->isArray(), '->isArray() returns true if the option can be an array'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE | sfCommandOption::IS_ARRAY); $t->ok($option->isArray(), '->isArray() returns true if the option can be an array'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE); $t->ok(!$option->isArray(), '->isArray() returns false if the option can not be an array'); // ->getHelp() $t->diag('->getHelp()'); $option = new sfCommandOption('foo', 'f', null, 'Some help'); $t->is($option->getHelp(), 'Some help', '->getHelp() returns the help message'); // ->getDefault() $t->diag('->getDefault()'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_OPTIONAL, '', 'default'); $t->is($option->getDefault(), 'default', '->getDefault() returns the default value'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_REQUIRED, '', 'default'); $t->is($option->getDefault(), 'default', '->getDefault() returns the default value'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_REQUIRED); $t->ok(null === $option->getDefault(), '->getDefault() returns null if no default value is configured'); $option = new sfCommandOption('foo', null, sfCommandOption::IS_ARRAY); $t->is($option->getDefault(), array(), '->getDefault() returns an empty array if option is an array'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE);
public function setOption(sfCommandOption $option, $value) { if ($option->isArray()) { $this->optionValues[$option->getName()][] = $value; } else { $this->optionValues[$option->getName()] = $value; } }