示例#1
0
$t->is($application->hasOptions(), true, '__construct() returns an application with an option');
$t->is($application->getOptions()->count(), 5, '__construct() returns an application with 5 options');
$t->comment('nbApplicationTest - Test run');
$foo = new DummyCommand('foo', null, new nbOptionSet(array(new nbOption('first', 'f'))));
$bar = new DummyCommand('bar', new nbArgumentSet(array(new nbArgument('first', nbArgument::REQUIRED))));
$bas = new DummyCommand('bas', null, new nbOptionSet(array(new nbOption('first', 'f'))));
$fas = new DummyCommand('fas');
$fas->setAlias('fou');
$application = new DummyApplication($serviceContainer);
//$application->setCommands(new nbCommandSet(array($foo, $bar, $bas, $fas)));
$serviceContainer->commandLoader->addCommands(array($foo, $bar, $bas, $fas));
$application->run('foo');
$t->ok($foo->hasExecuted(), '->run() executes command "foo"');
$application->run('bar test');
$t->ok($bar->hasExecuted(), '->run() executes command "bar test"');
$t->is($bar->getArgument('first'), 'test', '->run() executes command "bar test"');
$application->run('bas -f');
$t->ok($bas->hasExecuted(), '->run() executes command "bas -f"');
$t->is($bas->getOption('first'), true, '->run() executes command "bas -f"');
$application->run('fou');
$t->ok($fas->hasExecuted(), '->run() executes command "fas" with alias "fou"');
$t->comment('ApplicationTest - Test VerifyOption');
$application = new DummyApplication($serviceContainer, array(), array(new nbOption('option1')));
$foo = new DummyCommand('foo');
$foo->addOption(new nbOption('option1'));
$bar = new DummyCommand('bar');
$bar->addOption(new nbOption('option2'));
$list = new DummyCommand('list');
$serviceContainer->commandLoader->reset();
$serviceContainer->commandLoader->addCommands(array($foo, $bar, $list));
try {