/** * Add a sfCommandOption objects. * * @param sfCommandOption $option A sfCommandOption object */ public function addOption(sfCommandOption $option) { if (isset($this->options[$option->getName()])) { throw new sfCommandException(sprintf('An option named "%s" already exist.', $option->getName())); } else { if (isset($this->shortcuts[$option->getShortcut()])) { throw new sfCommandException(sprintf('An option with shortcut "%s" already exist.', $option->getShortcut())); } } $this->options[$option->getName()] = $option; if ($option->getShortcut()) { $this->shortcuts[$option->getShortcut()] = $option->getName(); } }
* For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(34); // __construct() $t->diag('__construct()'); $option = new sfCommandOption('foo'); $t->is($option->getName(), 'foo', '__construct() takes a name as its first argument'); $option = new sfCommandOption('--foo'); $t->is($option->getName(), 'foo', '__construct() removes the leading -- of the option name'); // shortcut argument $option = new sfCommandOption('foo', 'f'); $t->is($option->getShortcut(), 'f', '__construct() can take a shortcut as its second argument'); $option = new sfCommandOption('foo', '-f'); $t->is($option->getShortcut(), 'f', '__construct() removes the leading - of the shortcut'); // mode argument $option = new sfCommandOption('foo', 'f'); $t->is($option->acceptParameter(), false, '__construct() gives a "sfCommandOption::PARAMETER_NONE" mode by default'); $t->is($option->isParameterRequired(), false, '__construct() gives a "sfCommandOption::PARAMETER_NONE" mode by default'); $t->is($option->isParameterOptional(), false, '__construct() gives a "sfCommandOption::PARAMETER_NONE" mode by default'); $option = new sfCommandOption('foo', 'f', null); $t->is($option->acceptParameter(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_NONE); $t->is($option->acceptParameter(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_REQUIRED); $t->is($option->acceptParameter(), true, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode');