Exemplo n.º 1
0
}
// ->hasOption()
$t->diag('->hasOption()');
$optionSet = new sfCommandOptionSet();
$optionSet->addOptions(array($foo));
$t->is($optionSet->hasOption('foo'), true, '->hasOption() returns true if a sfCommandOption exists for the given name');
$t->is($optionSet->hasOption('bar'), false, '->hasOption() returns false if a sfCommandOption exists for the given name');
// ->hasShortcut()
$t->diag('->hasShortcut()');
$optionSet = new sfCommandOptionSet();
$optionSet->addOptions(array($foo));
$t->is($optionSet->hasShortcut('f'), true, '->hasShortcut() returns true if a sfCommandOption exists for the given shortcut');
$t->is($optionSet->hasShortcut('b'), false, '->hasShortcut() returns false if a sfCommandOption exists for the given shortcut');
// ->getOptionForShortcut()
$t->diag('->getOptionForShortcut()');
$optionSet = new sfCommandOptionSet();
$optionSet->addOptions(array($foo));
$t->is($optionSet->getOptionForShortcut('f'), $foo, '->getOptionForShortcut() returns a sfCommandOption by its shortcut');
try {
    $optionSet->getOptionForShortcut('l');
    $t->fail('->getOption() throws an exception if the shortcut does not exist');
} catch (sfCommandException $e) {
    $t->pass('->getOption() throws an exception if the shortcut does not exist');
}
// ->getDefaults()
$t->diag('->getDefaults()');
$optionSet = new sfCommandOptionSet();
$optionSet->addOptions(array(new sfCommandOption('foo1', null, sfCommandOption::PARAMETER_NONE), new sfCommandOption('foo2', null, sfCommandOption::PARAMETER_REQUIRED), new sfCommandOption('foo3', null, sfCommandOption::PARAMETER_REQUIRED, '', 'default'), new sfCommandOption('foo4', null, sfCommandOption::PARAMETER_OPTIONAL), new sfCommandOption('foo5', null, sfCommandOption::PARAMETER_OPTIONAL, '', 'default'), new sfCommandOption('foo6', null, sfCommandOption::PARAMETER_OPTIONAL | sfCommandOption::IS_ARRAY), new sfCommandOption('foo7', null, sfCommandOption::PARAMETER_OPTIONAL | sfCommandOption::IS_ARRAY, '', array(1, 2))));
$defaults = array('foo1' => null, 'foo2' => null, 'foo3' => 'default', 'foo4' => null, 'foo5' => 'default', 'foo6' => array(), 'foo7' => array(1, 2));
$t->is($optionSet->getDefaults(), $defaults, '->getDefaults() returns the default values for all options');