Ejemplo n.º 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\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');
Ejemplo n.º 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\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');
Ejemplo n.º 3
0
$t->is($application->asText('foo'), file_get_contents($fixtures . '/application_astext2.txt'), '->asText() returns a text representation of the application');
// ->asXml()
$t->diag('->asXml()');
$application = new Application();
$application->addCommand(new FooCommand());
$t->is($application->asXml(), file_get_contents($fixtures . '/application_asxml1.txt'), '->asXml() returns an XML representation of the application');
$t->is($application->asXml('foo'), file_get_contents($fixtures . '/application_asxml2.txt'), '->asXml() returns an XML representation of the application');
// ->renderException()
$t->diag('->renderException()');
$application = new Application();
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
$t->is($tester->getDisplay(), file_get_contents($fixtures . '/application_renderexception1.txt'), '->renderException() renders a pretty exception');
$tester->run(array('command' => 'foo'), array('verbosity' => Output::VERBOSITY_VERBOSE));
$t->like($tester->getDisplay(), '/Exception trace/', '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
$tester->run(array('command' => 'list', '--foo' => true));
$t->is($tester->getDisplay(), file_get_contents($fixtures . '/application_renderexception2.txt'), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
// ->run()
$t->diag('->run()');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->addCommand($command = new Foo1Command());
$_SERVER['argv'] = array('cli.php', 'foo:bar1');
ob_start();
$application->run();
ob_end_clean();
$t->is(get_class($command->input), 'Symfony\\Components\\CLI\\Input\\ArgvInput', '->run() creates an ArgvInput by default if none is given');
$t->is(get_class($command->output), 'Symfony\\Components\\CLI\\Output\\ConsoleOutput', '->run() creates a ConsoleOutput by default if none is given');
$application = new Application();