Пример #1
0
// ->getHelp()
$t->diag('->getHelp()');
$application = new Application();
$t->is($application->getHelp(), file_get_contents($fixtures . '/application_gethelp.txt'), '->setHelp() returns a help message');
// ->getCommands()
$t->diag('->getCommands()');
$application = new Application();
$commands = $application->getCommands();
$t->is(get_class($commands['help']), 'Symfony\\Components\\CLI\\Command\\HelpCommand', '->getCommands() returns the registered commands');
$application->addCommand(new FooCommand());
$commands = $application->getCommands('foo');
$t->is(count($commands), 1, '->getCommands() takes a namespace as its first argument');
// ->register()
$t->diag('->register()');
$application = new Application();
$command = $application->register('foo');
$t->is($command->getName(), 'foo', '->register() regiters a new command');
// ->addCommand() ->addCommands()
$t->diag('->addCommand() ->addCommands()');
$application = new Application();
$application->addCommand($foo = new FooCommand());
$commands = $application->getCommands();
$t->is($commands['foo:bar'], $foo, '->addCommand() registers a command');
$application = new Application();
$application->addCommands(array($foo = new FooCommand(), $foo1 = new Foo1Command()));
$commands = $application->getCommands();
$t->is(array($commands['foo:bar'], $commands['foo:bar1']), array($foo, $foo1), '->addCommands() registers an array of commands');
// ->hasCommand() ->getCommand()
$t->diag('->hasCommand() ->getCommand()');
$application = new Application();
$t->ok($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered');
Пример #2
0
/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Application;
use Symfony\Components\CLI\Output\Output;
use Symfony\Components\CLI\Tester\ApplicationTester;
$t = new LimeTest(6);
$application = new Application();
$application->setAutoExit(false);
$application->register('foo')->addArgument('command')->addArgument('foo')->setCode(function ($input, $output) {
    $output->write('foo');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo', 'foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
// ->run()
$t->diag('->run()');
$t->is($tester->getInput()->isInteractive(), false, '->execute() takes an interactive option');
$t->is($tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option');
$t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option');
// ->getInput()
$t->diag('->getInput()');
$t->is($tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance');
// ->getOutput()
$t->diag('->getOutput()');
rewind($tester->getOutput()->getStream());