Example #1
0
$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 {
    $application->run('foo');
    $t->fail('nbApplication::verifyOption() throws if there are some options in beeApplication and in new command');
} catch (Exception $e) {
    $t->pass('nbApplication::verifyOption() throws if there are some options in beeApplication and in new command');
}
Example #2
0
<?php

require_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new lime_test();
$fooArgument = new nbArgument('foo');
$barOption = new nbOption('bar');
$command1 = new DummyCommand("ns2:bas", new nbArgumentSet(array($fooArgument)), new nbOptionSet(array($barOption)));
$command1->setBriefDescription('brief description');
$aliasCommand = new nbAliasCommand('ns:alias', $command1);
$t->comment('nbAliasCommandTest - Test fullname');
$t->is($aliasCommand->getFullname(), "ns:alias", '->getFullName() returns a name without ":"');
$t->comment('nbAliasCommandTest - Test arguments');
$t->is($aliasCommand->getArguments()->count(), 1, '->getArguments() returns 1 argument');
$t->is($aliasCommand->getOptions()->count(), 2, '->getOptions() returns 1 options');
$t->comment('nbAliasCommandTest - Test description');
$t->is($aliasCommand->getBriefDescription(), "brief description", '->getBriefDescription() returns a the contained command description');
$t->comment('nbAliasCommandTest - Test run (success)');
$t->ok($aliasCommand->run(new nbCommandLineParser(), ''));
$t->ok($command1->hasExecuted());
$t->comment('nbAliasCommandTest - Test run (failure)');
$command1->failOnExecute();
$t->ok(!$aliasCommand->run(new nbCommandLineParser(), ''));
$t->ok($command1->hasExecuted());