Example #1
0
<?php

/*
 * 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\Tester\CommandTester;
use Symfony\Components\CLI\Command\HelpCommand;
use Symfony\Components\CLI\Command\ListCommand;
use Symfony\Components\CLI\Application;
$t = new LimeTest(4);
// ->execute()
$t->diag('->execute()');
$command = new HelpCommand();
$command->setCommand(new ListCommand());
$commandTester = new CommandTester($command);
$commandTester->execute(array());
$t->like($commandTester->getDisplay(), '/list \\[--xml\\] \\[namespace\\]/', '->execute() returns a text help for the given command');
$commandTester->execute(array('--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
$application = new Application();
$commandTester = new CommandTester($application->getCommand('help'));
$commandTester->execute(array('command_name' => 'list'));
$t->like($commandTester->getDisplay(), '/list \\[--xml\\] \\[namespace\\]/', '->execute() returns a text help for the given command');
$commandTester->execute(array('command_name' => 'list', '--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
Example #2
0
<?php

/*
 * 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\Tester\CommandTester;
use Symfony\Components\CLI\Application;
$t = new LimeTest(2);
$application = new Application();
// ->execute()
$t->diag('->execute()');
$commandTester = new CommandTester($application->getCommand('list'));
$commandTester->execute(array());
$t->like($commandTester->getDisplay(), '/help   Displays help for a command/', '->execute() returns a list of available commands');
$commandTester->execute(array('--xml' => true));
$t->like($commandTester->getDisplay(), '/<command id="list" namespace="_global" name="list">/', '->execute() returns a list of available commands in XML if --xml is passed');
<?php

/*
 * 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()');
Example #4
0
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('--color' => true));
$t->ok($tester->getOutput()->isDecorated(), '->run() forces color output if --color is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('--version' => true));
$t->is($tester->getDisplay(), file_get_contents($fixtures . '/application_run4.txt'), '->run() displays the program version if --version is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'list', '--quiet' => true));
$t->is($tester->getDisplay(), '', '->run() removes all output if --quiet is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'list', '--verbose' => true));
$t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->run() sets the output to verbose is --verbose is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->addCommand(new FooCommand());
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo:bar', '--no-interaction' => true));
$t->is($tester->getDisplay(), "called\n", '->run() does not called interact() if --no-interaction is passed');
Example #5
0
$t->is($command->getHelp(), 'help', '->getHelp() returns the help');
$ret = $command->setHelp('help1');
$t->is($ret, $command, '->setHelp() implements a fluent interface');
$t->is($command->getHelp(), 'help1', '->setHelp() sets the help');
// ->getAliases() ->setAliases()
$t->diag('->getAliases() ->setAliases()');
$t->is($command->getAliases(), array('name'), '->getAliases() returns the aliases');
$ret = $command->setAliases(array('name1'));
$t->is($ret, $command, '->setAliases() implements a fluent interface');
$t->is($command->getAliases(), array('name1'), '->setAliases() sets the aliases');
// ->getSynopsis()
$t->diag('->getSynopsis()');
$t->is($command->getSynopsis(), '%s foobar:bar [--foo] [foo]', '->getSynopsis() returns the synopsis');
// ->mergeApplicationDefinition()
$t->diag('->mergeApplicationDefinition()');
$application1 = new Application();
$application1->getDefinition()->addArguments(array(new Argument('foo')));
$application1->getDefinition()->addOptions(array(new Option('bar')));
$command = new TestCommand();
$command->setApplication($application1);
$command->setDefinition($definition = new Definition(array(new Argument('bar'), new Option('foo'))));
$command->mergeApplicationDefinition();
$t->ok($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$t->ok($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$t->ok($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options');
$t->ok($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');
$command->mergeApplicationDefinition();
$t->is($command->getDefinition()->getArgumentCount(), 3, '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
$command = new TestCommand();
$command->mergeApplicationDefinition();
$t->pass('->mergeApplicationDefinition() does nothing if application is not set');