Esempio n. 1
0
$t->is($set->countRequired(), 1, '->countRequired() returns the number of required options');
// ->count()
$t->comment('nbOptionSetTest - Test get option count');
$set = new nbOptionSet();
$set->addOption($foo);
$t->is($set->count(), 1, '->count() returns the number of options');
$set->addOption($bar);
$t->is($set->count(), 2, '->count() returns the number of options');
// ->getDefaultValues()
$t->comment('nbOptionSetTest - Test get values');
$set = new nbOptionSet();
$set->addOptions(array(new nbOption('foo', '', nbOption::PARAMETER_REQUIRED), new nbOption('foo1', '', nbOption::PARAMETER_OPTIONAL), new nbOption('foo2', '', nbOption::PARAMETER_OPTIONAL, '', 'default'), new nbOption('foo3', '', nbOption::PARAMETER_OPTIONAL | nbOption::IS_ARRAY)));
$t->is($set->getDefaultValues(), array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), '->getDefaultValues() returns the default values for each option');
$set = new nbOptionSet();
$set->addOptions(array(new nbOption('foo4', '', nbOption::PARAMETER_OPTIONAL | nbOption::IS_ARRAY, '', array(1, 2))));
$t->is($set->getDefaultValues(), array('foo4' => array(1, 2)), '->getDefaultValues() return the default values for each option');
$t->comment('nbOptionSet - Test shortcuts');
$set = new nbOptionSet(array(new nbOption('foo', 'f'), new nbOption('bar', 'b'), new nbOption('bas', '')));
$t->is($set->hasShortcut('f'), true, '->hasShortcut() returns true for shortcut "f"');
$t->is($set->hasShortcut('u'), false, '->hasShortcut() returns false for shortcut "u"');
$t->isa_ok($set->getByShortcut('f'), 'nbOption', '->getByShortcut() returns a valid option for shortcut "f"');
try {
    $set->getByShortcut('u');
    $t->fail('->getByShortcut() throw a RangeException for shortcut "u"');
} catch (RangeException $e) {
    $t->pass('->getByShortcut() throw a RangeException for shortcut "u"');
}
$t->comment('nbOptionSet - Test to string');
$set = new nbOptionSet();
$t->is((string) $set, '', '->__toString() returns ""');
$set = new nbOptionSet(array($foo));