the whole shebang

This commit is contained in:
2014-11-25 16:42:40 +01:00
parent 7f74c0613e
commit ab1334c0cf
3686 changed files with 496409 additions and 1 deletions

View File

@@ -0,0 +1,837 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
class ApplicationTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = realpath(__DIR__.'/Fixtures/');
require_once self::$fixturesPath.'/FooCommand.php';
require_once self::$fixturesPath.'/Foo1Command.php';
require_once self::$fixturesPath.'/Foo2Command.php';
require_once self::$fixturesPath.'/Foo3Command.php';
require_once self::$fixturesPath.'/Foo4Command.php';
}
protected function normalizeLineBreaks($text)
{
return str_replace(PHP_EOL, "\n", $text);
}
/**
* Replaces the dynamic placeholders of the command help text with a static version.
* The placeholder %command.full_name% includes the script path that is not predictable
* and can not be tested against.
*/
protected function ensureStaticCommandHelp(Application $application)
{
foreach ($application->all() as $command) {
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
}
public function testConstructor()
{
$application = new Application('foo', 'bar');
$this->assertEquals('foo', $application->getName(), '__construct() takes the application name as its first argument');
$this->assertEquals('bar', $application->getVersion(), '__construct() takes the application version as its second argument');
$this->assertEquals(array('help', 'list'), array_keys($application->all()), '__construct() registered the help and list commands by default');
}
public function testSetGetName()
{
$application = new Application();
$application->setName('foo');
$this->assertEquals('foo', $application->getName(), '->setName() sets the name of the application');
}
public function testSetGetVersion()
{
$application = new Application();
$application->setVersion('bar');
$this->assertEquals('bar', $application->getVersion(), '->setVersion() sets the version of the application');
}
public function testGetLongVersion()
{
$application = new Application('foo', 'bar');
$this->assertEquals('<info>foo</info> version <comment>bar</comment>', $application->getLongVersion(), '->getLongVersion() returns the long version of the application');
}
public function testHelp()
{
$application = new Application();
$this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->setHelp() returns a help message');
}
public function testAll()
{
$application = new Application();
$commands = $application->all();
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
$application->add(new \FooCommand());
$commands = $application->all('foo');
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
}
public function testRegister()
{
$application = new Application();
$command = $application->register('foo');
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
}
public function testAdd()
{
$application = new Application();
$application->add($foo = new \FooCommand());
$commands = $application->all();
$this->assertEquals($foo, $commands['foo:bar'], '->add() registers a command');
$application = new Application();
$application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
$commands = $application->all();
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
}
public function testHasGet()
{
$application = new Application();
$this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
$this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
$application->add($foo = new \FooCommand());
$this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
$this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
$this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
$application = new Application();
$application->add($foo = new \FooCommand());
// simulate --help
$r = new \ReflectionObject($application);
$p = $r->getProperty('wantHelps');
$p->setAccessible(true);
$p->setValue($application, true);
$command = $application->get('foo:bar');
$this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $command, '->get() returns the help command if --help is provided as the input');
}
public function testSilentHelp()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('-h' => true, '-q' => true), array('decorated' => false));
$this->assertEmpty($tester->getDisplay(true));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The command "foofoo" does not exist.
*/
public function testGetInvalidCommand()
{
$application = new Application();
$application->get('foofoo');
}
public function testGetNamespaces()
{
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$this->assertEquals(array('foo'), $application->getNamespaces(), '->getNamespaces() returns an array of unique used namespaces');
}
public function testFindNamespace()
{
$application = new Application();
$application->add(new \FooCommand());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
$this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
$application->add(new \Foo2Command());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1).
*/
public function testFindAmbiguousNamespace()
{
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo2Command());
$application->findNamespace('f');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
*/
public function testFindInvalidNamespace()
{
$application = new Application();
$application->findNamespace('bar');
}
public function testFind()
{
$application = new Application();
$application->add(new \FooCommand());
$this->assertInstanceOf('FooCommand', $application->find('foo:bar'), '->find() returns a command if its name exists');
$this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $application->find('h'), '->find() returns a command if its name exists');
$this->assertInstanceOf('FooCommand', $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists');
$this->assertInstanceOf('FooCommand', $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist');
$this->assertInstanceOf('FooCommand', $application->find('a'), '->find() returns a command if the abbreviation exists for an alias');
}
/**
* @dataProvider provideAmbiguousAbbreviations
*/
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
{
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$application->add(new \Foo2Command());
$application->find($abbreviation);
}
public function provideAmbiguousAbbreviations()
{
return array(
array('f', 'Command "f" is not defined.'),
array('a', 'Command "a" is ambiguous (afoobar, afoobar1 and 1 more).'),
array('foo:b', 'Command "foo:b" is ambiguous (foo:bar, foo:bar1).')
);
}
public function testFindCommandEqualNamespace()
{
$application = new Application();
$application->add(new \Foo3Command());
$application->add(new \Foo4Command());
$this->assertInstanceOf('Foo3Command', $application->find('foo3:bar'), '->find() returns the good command even if a namespace has same name');
$this->assertInstanceOf('Foo4Command', $application->find('foo3:bar:toh'), '->find() returns a command even if its namespace equals another command name');
}
/**
* @dataProvider provideInvalidCommandNamesSingle
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Did you mean this
*/
public function testFindAlternativeExceptionMessageSingle($name)
{
$application = new Application();
$application->add(new \FooCommand());
$application->find($name);
}
public function provideInvalidCommandNamesSingle()
{
return array(
array('foo:baR'),
array('foO:bar')
);
}
public function testFindAlternativeExceptionMessageMultiple()
{
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$application->add(new \Foo2Command());
// Command + plural
try {
$application->find('foo:baR');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
}
// Namespace + plural
try {
$application->find('foo2:bar');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
}
$application->add(new \Foo3Command());
$application->add(new \Foo4Command());
// Subnamespace + plural
try {
$a = $application->find('foo3:');
$this->fail('->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e);
$this->assertRegExp('/foo3:bar/', $e->getMessage());
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
}
}
public function testFindAlternativeCommands()
{
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$application->add(new \Foo2Command());
try {
$application->find($commandName = 'Unknown command');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
$this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without alternatives');
}
try {
$application->find($commandName = 'foo');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertRegExp('/foo:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar"');
$this->assertRegExp('/foo1:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo1:bar"');
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
}
// Test if "foo1" command throw an "\InvalidArgumentException" and does not contain
// "foo:bar" as alternative because "foo1" is too far from "foo:bar"
try {
$application->find($commandName = 'foo1');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertFalse(strpos($e->getMessage(), 'foo:bar'), '->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative');
}
}
public function testFindAlternativeNamespace()
{
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$application->add(new \Foo2Command());
$application->add(new \foo3Command());
try {
$application->find('Unknown-namespace:Unknown-command');
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
$this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, without alternatives');
}
try {
$application->find('foo2:command');
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative');
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"');
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
}
}
public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
{
$application = $this->getMock('Symfony\Component\Console\Application', array('getNamespaces'));
$application->expects($this->once())
->method('getNamespaces')
->will($this->returnValue(array('foo:sublong', 'bar:sub')));
$this->assertEquals('foo:sublong', $application->findNamespace('f:sub'));
}
public function testSetCatchExceptions()
{
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
->will($this->returnValue(120));
$tester = new ApplicationTester($application);
$application->setCatchExceptions(true);
$tester->run(array('command' => 'foo'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');
$application->setCatchExceptions(false);
try {
$tester->run(array('command' => 'foo'), array('decorated' => false));
$this->fail('->setCatchExceptions() sets the catch exception flag');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
$this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
}
}
public function testAsText()
{
$application = new Application();
$application->add(new \FooCommand);
$this->ensureStaticCommandHelp($application);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application');
}
public function testAsXml()
{
$application = new Application();
$application->add(new \FooCommand);
$this->ensureStaticCommandHelp($application);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
}
public function testRenderException()
{
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
->will($this->returnValue(120));
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->renderException() renders a pretty exception');
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
$this->assertContains('Exception trace', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
$tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getDisplay(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
$application->add(new \Foo3Command);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
->will($this->returnValue(32));
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
}
public function testRun()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->add($command = new \Foo1Command());
$_SERVER['argv'] = array('cli.php', 'foo:bar1');
ob_start();
$application->run();
ob_end_clean();
$this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
$this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$this->ensureStaticCommandHelp($application);
$tester = new ApplicationTester($application);
$tester->run(array(), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $tester->getDisplay(true), '->run() runs the list command if no argument is passed');
$tester->run(array('--help' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if --help is passed');
$tester->run(array('-h' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if -h is passed');
$tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if --help is passed');
$tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if -h is passed');
$tester->run(array('--ansi' => true));
$this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
$tester->run(array('--no-ansi' => true));
$this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
$tester->run(array('--version' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if --version is passed');
$tester->run(array('-V' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if -v is passed');
$tester->run(array('command' => 'list', '--quiet' => true));
$this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
$tester->run(array('command' => 'list', '-q' => true));
$this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');
$tester->run(array('command' => 'list', '--verbose' => true));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
$tester->run(array('command' => 'list', '--verbose' => 1));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed');
$tester->run(array('command' => 'list', '--verbose' => 2));
$this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed');
$tester->run(array('command' => 'list', '--verbose' => 3));
$this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');
$tester->run(array('command' => 'list', '--verbose' => 4));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');
$tester->run(array('command' => 'list', '-v' => true));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
$tester->run(array('command' => 'list', '-vv' => true));
$this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
$tester->run(array('command' => 'list', '-vvv' => true));
$this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->add(new \FooCommand());
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo:bar', '--no-interaction' => true), array('decorated' => false));
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');
$tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
}
public function testRunReturnsIntegerExitCode()
{
$exception = new \Exception('', 4);
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
$application->setAutoExit(false);
$application->expects($this->once())
->method('doRun')
->will($this->throwException($exception));
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
}
public function testRunReturnsExitCodeOneForExceptionCodeZero()
{
$exception = new \Exception('', 0);
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
$application->setAutoExit(false);
$application->expects($this->once())
->method('doRun')
->will($this->throwException($exception));
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
}
/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData
*/
public function testAddingAlreadySetDefinitionElementData($def)
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application
->register('foo')
->setDefinition(array($def))
->setCode(function (InputInterface $input, OutputInterface $output) {})
;
$input = new ArrayInput(array('command' => 'foo'));
$output = new NullOutput();
$application->run($input, $output);
}
public function getAddingAlreadySetDefinitionElementData()
{
return array(
array(new InputArgument('command', InputArgument::REQUIRED)),
array(new InputOption('quiet', '', InputOption::VALUE_NONE)),
array(new InputOption('query', 'q', InputOption::VALUE_NONE)),
);
}
public function testGetDefaultHelperSetReturnsDefaultValues()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$helperSet = $application->getHelperSet();
$this->assertTrue($helperSet->has('formatter'));
$this->assertTrue($helperSet->has('dialog'));
$this->assertTrue($helperSet->has('progress'));
}
public function testAddingSingleHelperSetOverwritesDefaultValues()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->setHelperSet(new HelperSet(array(new FormatterHelper())));
$helperSet = $application->getHelperSet();
$this->assertTrue($helperSet->has('formatter'));
// no other default helper set should be returned
$this->assertFalse($helperSet->has('dialog'));
$this->assertFalse($helperSet->has('progress'));
}
public function testOverwritingDefaultHelperSetOverwritesDefaultValues()
{
$application = new CustomApplication();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->setHelperSet(new HelperSet(array(new FormatterHelper())));
$helperSet = $application->getHelperSet();
$this->assertTrue($helperSet->has('formatter'));
// no other default helper set should be returned
$this->assertFalse($helperSet->has('dialog'));
$this->assertFalse($helperSet->has('progress'));
}
public function testGetDefaultInputDefinitionReturnsDefaultValues()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$inputDefinition = $application->getDefinition();
$this->assertTrue($inputDefinition->hasArgument('command'));
$this->assertTrue($inputDefinition->hasOption('help'));
$this->assertTrue($inputDefinition->hasOption('quiet'));
$this->assertTrue($inputDefinition->hasOption('verbose'));
$this->assertTrue($inputDefinition->hasOption('version'));
$this->assertTrue($inputDefinition->hasOption('ansi'));
$this->assertTrue($inputDefinition->hasOption('no-ansi'));
$this->assertTrue($inputDefinition->hasOption('no-interaction'));
}
public function testOverwritingDefaultInputDefinitionOverwritesDefaultValues()
{
$application = new CustomApplication();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$inputDefinition = $application->getDefinition();
// check whether the default arguments and options are not returned any more
$this->assertFalse($inputDefinition->hasArgument('command'));
$this->assertFalse($inputDefinition->hasOption('help'));
$this->assertFalse($inputDefinition->hasOption('quiet'));
$this->assertFalse($inputDefinition->hasOption('verbose'));
$this->assertFalse($inputDefinition->hasOption('version'));
$this->assertFalse($inputDefinition->hasOption('ansi'));
$this->assertFalse($inputDefinition->hasOption('no-ansi'));
$this->assertFalse($inputDefinition->hasOption('no-interaction'));
$this->assertTrue($inputDefinition->hasOption('custom'));
}
public function testSettingCustomInputDefinitionOverwritesDefaultValues()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->setDefinition(new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.'))));
$inputDefinition = $application->getDefinition();
// check whether the default arguments and options are not returned any more
$this->assertFalse($inputDefinition->hasArgument('command'));
$this->assertFalse($inputDefinition->hasOption('help'));
$this->assertFalse($inputDefinition->hasOption('quiet'));
$this->assertFalse($inputDefinition->hasOption('verbose'));
$this->assertFalse($inputDefinition->hasOption('version'));
$this->assertFalse($inputDefinition->hasOption('ansi'));
$this->assertFalse($inputDefinition->hasOption('no-ansi'));
$this->assertFalse($inputDefinition->hasOption('no-interaction'));
$this->assertTrue($inputDefinition->hasOption('custom'));
}
public function testRunWithDispatcher()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher($this->getDispatcher());
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
$this->assertEquals('before.foo.after.', $tester->getDisplay());
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage caught
*/
public function testRunWithExceptionAndDispatcher()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
throw new \RuntimeException('foo');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
}
public function testRunDispatchesAllEventsWithException()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
throw new \RuntimeException('foo');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
}
protected function getDispatcher()
{
$dispatcher = new EventDispatcher;
$dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) {
$event->getOutput()->write('before.');
});
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) {
$event->getOutput()->write('after.');
$event->setExitCode(128);
});
$dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) {
$event->getOutput()->writeln('caught.');
$event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException()));
});
return $dispatcher;
}
}
class CustomApplication extends Application
{
/**
* Overwrites the default input definition.
*
* @return InputDefinition An InputDefinition instance
*/
protected function getDefaultInputDefinition()
{
return new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')));
}
/**
* Gets the default helper set with the helpers that should always be available.
*
* @return HelperSet A HelperSet instance
*/
protected function getDefaultHelperSet()
{
return new HelperSet(array(new FormatterHelper()));
}
}

View File

@@ -0,0 +1,338 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Tester\CommandTester;
class CommandTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = __DIR__.'/../Fixtures/';
require_once self::$fixturesPath.'/TestCommand.php';
}
public function testConstructor()
{
$command = new Command('foo:bar');
$this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument');
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage The command name cannot be empty.
*/
public function testCommandNameCannotBeEmpty()
{
new Command();
}
public function testSetApplication()
{
$application = new Application();
$command = new \TestCommand();
$command->setApplication($application);
$this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application');
}
public function testSetGetDefinition()
{
$command = new \TestCommand();
$ret = $command->setDefinition($definition = new InputDefinition());
$this->assertEquals($command, $ret, '->setDefinition() implements a fluent interface');
$this->assertEquals($definition, $command->getDefinition(), '->setDefinition() sets the current InputDefinition instance');
$command->setDefinition(array(new InputArgument('foo'), new InputOption('bar')));
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
$command->setDefinition(new InputDefinition());
}
public function testAddArgument()
{
$command = new \TestCommand();
$ret = $command->addArgument('foo');
$this->assertEquals($command, $ret, '->addArgument() implements a fluent interface');
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->addArgument() adds an argument to the command');
}
public function testAddOption()
{
$command = new \TestCommand();
$ret = $command->addOption('foo');
$this->assertEquals($command, $ret, '->addOption() implements a fluent interface');
$this->assertTrue($command->getDefinition()->hasOption('foo'), '->addOption() adds an option to the command');
}
public function testGetNamespaceGetNameSetName()
{
$command = new \TestCommand();
$this->assertEquals('namespace:name', $command->getName(), '->getName() returns the command name');
$command->setName('foo');
$this->assertEquals('foo', $command->getName(), '->setName() sets the command name');
$ret = $command->setName('foobar:bar');
$this->assertEquals($command, $ret, '->setName() implements a fluent interface');
$this->assertEquals('foobar:bar', $command->getName(), '->setName() sets the command name');
}
/**
* @dataProvider provideInvalidCommandNames
*/
public function testInvalidCommandNames($name)
{
$this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name));
$command = new \TestCommand();
$command->setName($name);
}
public function provideInvalidCommandNames()
{
return array(
array(''),
array('foo:')
);
}
public function testGetSetDescription()
{
$command = new \TestCommand();
$this->assertEquals('description', $command->getDescription(), '->getDescription() returns the description');
$ret = $command->setDescription('description1');
$this->assertEquals($command, $ret, '->setDescription() implements a fluent interface');
$this->assertEquals('description1', $command->getDescription(), '->setDescription() sets the description');
}
public function testGetSetHelp()
{
$command = new \TestCommand();
$this->assertEquals('help', $command->getHelp(), '->getHelp() returns the help');
$ret = $command->setHelp('help1');
$this->assertEquals($command, $ret, '->setHelp() implements a fluent interface');
$this->assertEquals('help1', $command->getHelp(), '->setHelp() sets the help');
}
public function testGetProcessedHelp()
{
$command = new \TestCommand();
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly');
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name%');
}
public function testGetSetAliases()
{
$command = new \TestCommand();
$this->assertEquals(array('name'), $command->getAliases(), '->getAliases() returns the aliases');
$ret = $command->setAliases(array('name1'));
$this->assertEquals($command, $ret, '->setAliases() implements a fluent interface');
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
}
public function testGetSynopsis()
{
$command = new \TestCommand();
$command->addOption('foo');
$command->addArgument('foo');
$this->assertEquals('namespace:name [--foo] [foo]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
}
public function testGetHelper()
{
$application = new Application();
$command = new \TestCommand();
$command->setApplication($application);
$formatterHelper = new FormatterHelper();
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->getHelper() returns the correct helper');
}
public function testGet()
{
$application = new Application();
$command = new \TestCommand();
$command->setApplication($application);
$formatterHelper = new FormatterHelper();
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->__get() returns the correct helper');
}
public function testMergeApplicationDefinition()
{
$application1 = new Application();
$application1->getDefinition()->addArguments(array(new InputArgument('foo')));
$application1->getDefinition()->addOptions(array(new InputOption('bar')));
$command = new \TestCommand();
$command->setApplication($application1);
$command->setDefinition($definition = new InputDefinition(array(new InputArgument('bar'), new InputOption('foo'))));
$r = new \ReflectionObject($command);
$m = $r->getMethod('mergeApplicationDefinition');
$m->setAccessible(true);
$m->invoke($command);
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$this->assertTrue($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$this->assertTrue($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options');
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');
$m->invoke($command);
$this->assertEquals(3, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
}
public function testMergeApplicationDefinitionWithoutArgsThenWithArgsAddsArgs()
{
$application1 = new Application();
$application1->getDefinition()->addArguments(array(new InputArgument('foo')));
$application1->getDefinition()->addOptions(array(new InputOption('bar')));
$command = new \TestCommand();
$command->setApplication($application1);
$command->setDefinition($definition = new InputDefinition(array()));
$r = new \ReflectionObject($command);
$m = $r->getMethod('mergeApplicationDefinition');
$m->setAccessible(true);
$m->invoke($command, false);
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition(false) merges the application and the commmand options');
$this->assertFalse($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(false) does not merge the application arguments');
$m->invoke($command, true);
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(true) merges the application arguments and the command arguments');
$m->invoke($command);
$this->assertEquals(2, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments');
}
public function testRunInteractive()
{
$tester = new CommandTester(new \TestCommand());
$tester->execute(array(), array('interactive' => true));
$this->assertEquals('interact called'.PHP_EOL.'execute called'.PHP_EOL, $tester->getDisplay(), '->run() calls the interact() method if the input is interactive');
}
public function testRunNonInteractive()
{
$tester = new CommandTester(new \TestCommand());
$tester->execute(array(), array('interactive' => false));
$this->assertEquals('execute called'.PHP_EOL, $tester->getDisplay(), '->run() does not call the interact() method if the input is not interactive');
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage You must override the execute() method in the concrete command class.
*/
public function testExecuteMethodNeedsToBeOverriden()
{
$command = new Command('foo');
$command->run(new StringInput(''), new NullOutput());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "--bar" option does not exist.
*/
public function testRunWithInvalidOption()
{
$command = new \TestCommand();
$tester = new CommandTester($command);
$tester->execute(array('--bar' => true));
}
public function testRunReturnsIntegerExitCode()
{
$command = new \TestCommand();
$exitCode = $command->run(new StringInput(''), new NullOutput());
$this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)');
$command = $this->getMock('TestCommand', array('execute'));
$command->expects($this->once())
->method('execute')
->will($this->returnValue('2.3'));
$exitCode = $command->run(new StringInput(''), new NullOutput());
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
}
public function testRunReturnsAlwaysInteger()
{
$command = new \TestCommand();
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
}
public function testSetCode()
{
$command = new \TestCommand();
$ret = $command->setCode(function (InputInterface $input, OutputInterface $output) {
$output->writeln('from the code...');
});
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
$tester = new CommandTester($command);
$tester->execute(array());
$this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay());
}
public function testSetCodeWithNonClosureCallable()
{
$command = new \TestCommand();
$ret = $command->setCode(array($this, 'callableMethodCommand'));
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
$tester = new CommandTester($command);
$tester->execute(array());
$this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid callable provided to Command::setCode.
*/
public function testSetCodeWithNonCallable()
{
$command = new \TestCommand();
$command->setCode(array($this, 'nonExistentMethod'));
}
public function callableMethodCommand(InputInterface $input, OutputInterface $output)
{
$output->writeln('from the code...');
}
public function testAsText()
{
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array('command' => $command->getName()));
$this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command');
}
public function testAsXml()
{
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array('command' => $command->getName()));
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Application;
class HelpCommandTest extends \PHPUnit_Framework_TestCase
{
public function testExecuteForCommandAlias()
{
$command = new HelpCommand();
$command->setApplication(new Application());
$commandTester = new CommandTester($command);
$commandTester->execute(array('command_name' => 'li'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
}
public function testExecuteForCommand()
{
$command = new HelpCommand();
$commandTester = new CommandTester($command);
$command->setCommand(new ListCommand());
$commandTester->execute(array());
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
}
public function testExecuteForCommandWithXmlOption()
{
$command = new HelpCommand();
$commandTester = new CommandTester($command);
$command->setCommand(new ListCommand());
$commandTester->execute(array('--format' => 'xml'));
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
}
public function testExecuteForApplicationCommand()
{
$application = new Application();
$commandTester = new CommandTester($application->get('help'));
$commandTester->execute(array('command_name' => 'list'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
}
public function testExecuteForApplicationCommandWithXmlOption()
{
$application = new Application();
$commandTester = new CommandTester($application->get('help'));
$commandTester->execute(array('command_name' => 'list', '--format' => 'xml'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Application;
class ListCommandTest extends \PHPUnit_Framework_TestCase
{
public function testExecuteListsCommands()
{
$application = new Application();
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
$this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
}
public function testExecuteListsCommandsWithXmlOption()
{
$application = new Application();
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
$this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
}
public function testExecuteListsCommandsWithRawOption()
{
$application = new Application();
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName(), '--raw' => true));
$output = <<<EOF
help Displays help for a command
list Lists commands
EOF;
$this->assertEquals($output, $commandTester->getDisplay(true));
}
public function testExecuteListsCommandsWithNamespaceArgument()
{
require_once(realpath(__DIR__.'/../Fixtures/FooCommand.php'));
$application = new Application();
$application->add(new \FooCommand());
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
$output = <<<EOF
foo:bar The foo:bar command
EOF;
$this->assertEquals($output, $commandTester->getDisplay(true));
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
{
/** @dataProvider getDescribeInputArgumentTestData */
public function testDescribeInputArgument(InputArgument $argument, $expectedDescription)
{
$this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($argument)));
}
/** @dataProvider getDescribeInputOptionTestData */
public function testDescribeInputOption(InputOption $option, $expectedDescription)
{
$this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($option)));
}
/** @dataProvider getDescribeInputDefinitionTestData */
public function testDescribeInputDefinition(InputDefinition $definition, $expectedDescription)
{
$this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($definition)));
}
/** @dataProvider getDescribeCommandTestData */
public function testDescribeCommand(Command $command, $expectedDescription)
{
$this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($command)));
}
/** @dataProvider getDescribeApplicationTestData */
public function testDescribeApplication(Application $application, $expectedDescription)
{
// Replaces the dynamic placeholders of the command help text with a static version.
// The placeholder %command.full_name% includes the script path that is not predictable
// and can not be tested against.
foreach ($application->all() as $command) {
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $this->getDescriptor()->describe($application))));
}
public function getDescribeInputArgumentTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputArguments());
}
public function getDescribeInputOptionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputOptions());
}
public function getDescribeInputDefinitionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputDefinitions());
}
public function getDescribeCommandTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getCommands());
}
public function getDescribeApplicationTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getApplications());
}
abstract protected function getDescriptor();
abstract protected function getFormat();
private function getDescriptionTestData(array $objects)
{
$data = array();
foreach ($objects as $name => $object) {
$description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $name, $this->getFormat()));
$data[] = array($object, $description);
}
return $data;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Descriptor\JsonDescriptor;
class JsonDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new JsonDescriptor();
}
protected function getFormat()
{
return 'json';
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
class MarkdownDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new MarkdownDescriptor();
}
protected function getFormat()
{
return 'md';
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication1;
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication2;
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand1;
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand2;
/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class ObjectsProvider
{
public static function getInputArguments()
{
return array(
'input_argument_1' => new InputArgument('argument_name', InputArgument::REQUIRED),
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
);
}
public static function getInputOptions()
{
return array(
'input_option_1' => new InputOption('option_name', 'o', InputOption::VALUE_NONE),
'input_option_2' => new InputOption('option_name', 'o', InputOption::VALUE_OPTIONAL, 'option description', 'default_value'),
'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'),
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
);
}
public static function getInputDefinitions()
{
return array(
'input_definition_1' => new InputDefinition(),
'input_definition_2' => new InputDefinition(array(new InputArgument('argument_name', InputArgument::REQUIRED))),
'input_definition_3' => new InputDefinition(array(new InputOption('option_name', 'o', InputOption::VALUE_NONE))),
'input_definition_4' => new InputDefinition(array(
new InputArgument('argument_name', InputArgument::REQUIRED),
new InputOption('option_name', 'o', InputOption::VALUE_NONE),
)),
);
}
public static function getCommands()
{
return array(
'command_1' => new DescriptorCommand1(),
'command_2' => new DescriptorCommand2(),
);
}
public static function getApplications()
{
return array(
'application_1' => new DescriptorApplication1(),
'application_2' => new DescriptorApplication2(),
);
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Descriptor\TextDescriptor;
class TextDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new TextDescriptor();
}
protected function getFormat()
{
return 'txt';
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
class XmlDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new XmlDescriptor();
}
protected function getFormat()
{
return 'xml';
}
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Fixtures;
use Symfony\Component\Console\Application;
class DescriptorApplication1 extends Application
{
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Fixtures;
use Symfony\Component\Console\Application;
class DescriptorApplication2 extends Application
{
public function __construct()
{
parent::__construct('My Symfony application', 'v1.0');
$this->add(new DescriptorCommand1());
$this->add(new DescriptorCommand2());
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Fixtures;
use Symfony\Component\Console\Command\Command;
class DescriptorCommand1 extends Command
{
protected function configure()
{
$this
->setName('descriptor:command1')
->setAliases(array('alias1', 'alias2'))
->setDescription('command 1 description')
->setHelp('command 1 help')
;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Fixtures;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class DescriptorCommand2 extends Command
{
protected function configure()
{
$this
->setName('descriptor:command2')
->setDescription('command 2 description')
->setHelp('command 2 help')
->addArgument('argument_name', InputArgument::REQUIRED)
->addOption('option_name', 'o', InputOption::VALUE_NONE)
;
}
}

View File

@@ -0,0 +1,26 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Foo1Command extends Command
{
public $input;
public $output;
protected function configure()
{
$this
->setName('foo:bar1')
->setDescription('The foo:bar1 command')
->setAliases(array('afoobar1'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
}
}

View File

@@ -0,0 +1,21 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Foo2Command extends Command
{
protected function configure()
{
$this
->setName('foo1:bar')
->setDescription('The foo1:bar command')
->setAliases(array('afoobar2'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
}
}

View File

@@ -0,0 +1,25 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Foo3Command extends Command
{
protected function configure()
{
$this
->setName('foo3:bar')
->setDescription('The foo3:bar command')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
throw new \Exception("First exception");
} catch (\Exception $e) {
throw new \Exception("Second exception", 0, $e);
}
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Symfony\Component\Console\Command\Command;
class Foo4Command extends Command
{
protected function configure()
{
$this->setName('foo3:bar:toh');
}
}

View File

@@ -0,0 +1,33 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class FooCommand extends Command
{
public $input;
public $output;
protected function configure()
{
$this
->setName('foo:bar')
->setDescription('The foo:bar command')
->setAliases(array('afoobar'))
;
}
protected function interact(InputInterface $input, OutputInterface $output)
{
$output->writeln('interact called');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$output->writeln('called');
}
}

View File

@@ -0,0 +1,28 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TestCommand extends Command
{
protected function configure()
{
$this
->setName('namespace:name')
->setAliases(array('name'))
->setDescription('description')
->setHelp('help')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('execute called');
}
protected function interact(InputInterface $input, OutputInterface $output)
{
$output->writeln('interact called');
}
}

View File

@@ -0,0 +1 @@
{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":null}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}

View File

@@ -0,0 +1,199 @@
UNKNOWN
=======
* help
* list
help
----
* Description: Displays help for a command
* Usage: `help [--xml] [--format="..."] [--raw] [command_name]`
* Aliases: <none>
The <info>help</info> command displays help for a given command:
<info>php app/console help list</info>
You can also output the help in other formats by using the <comment>--format</comment> option:
<info>php app/console help --format=xml list</info>
To display the list of available commands, please use the <info>list</info> command.
### Arguments:
**command_name:**
* Name: command_name
* Is required: no
* Is array: no
* Description: The command name
* Default: `'help'`
### Options:
**xml:**
* Name: `--xml`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output help as XML
* Default: `false`
**format:**
* Name: `--format`
* Shortcut: <none>
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: To output help in other formats
* Default: `NULL`
**raw:**
* Name: `--raw`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output raw command help
* Default: `false`
**help:**
* Name: `--help`
* Shortcut: `-h`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this help message.
* Default: `false`
**quiet:**
* Name: `--quiet`
* Shortcut: `-q`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not output any message.
* Default: `false`
**verbose:**
* Name: `--verbose`
* Shortcut: `-v|-vv|-vvv`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
* Default: `false`
**version:**
* Name: `--version`
* Shortcut: `-V`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this application version.
* Default: `false`
**ansi:**
* Name: `--ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Force ANSI output.
* Default: `false`
**no-ansi:**
* Name: `--no-ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Disable ANSI output.
* Default: `false`
**no-interaction:**
* Name: `--no-interaction`
* Shortcut: `-n`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not ask any interactive question.
* Default: `false`
list
----
* Description: Lists commands
* Usage: `list [--xml] [--raw] [--format="..."] [namespace]`
* Aliases: <none>
The <info>list</info> command lists all commands:
<info>php app/console list</info>
You can also display the commands for a specific namespace:
<info>php app/console list test</info>
You can also output the information in other formats by using the <comment>--format</comment> option:
<info>php app/console list --format=xml</info>
It's also possible to get raw list of commands (useful for embedding command runner):
<info>php app/console list --raw</info>
### Arguments:
**namespace:**
* Name: namespace
* Is required: no
* Is array: no
* Description: The namespace name
* Default: `NULL`
### Options:
**xml:**
* Name: `--xml`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output list as XML
* Default: `false`
**raw:**
* Name: `--raw`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output raw command list
* Default: `false`
**format:**
* Name: `--format`
* Shortcut: <none>
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: To output list in other formats
* Default: `NULL`

View File

@@ -0,0 +1,17 @@
<info>Console Tool</info>
<comment>Usage:</comment>
[options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
<comment>Available commands:</comment>
<info>help </info> Displays help for a command
<info>list </info> Lists commands

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony>
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
&lt;info&gt;php app/console help list&lt;/info&gt;
You can also output the help in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases/>
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
<defaults>
<default>help</default>
</defaults>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output help as XML</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
&lt;info&gt;php app/console list&lt;/info&gt;
You can also display the commands for a specific namespace:
&lt;info&gt;php app/console list test&lt;/info&gt;
You can also output the information in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console list --format=xml&lt;/info&gt;
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output list as XML</description>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
<defaults/>
</option>
</options>
</command>
</commands>
<namespaces>
<namespace id="_global">
<command>help</command>
<command>list</command>
</namespace>
</namespaces>
</symfony>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,388 @@
My Symfony application
======================
* alias1
* alias2
* help
* list
**descriptor:**
* descriptor:command1
* descriptor:command2
help
----
* Description: Displays help for a command
* Usage: `help [--xml] [--format="..."] [--raw] [command_name]`
* Aliases: <none>
The <info>help</info> command displays help for a given command:
<info>php app/console help list</info>
You can also output the help in other formats by using the <comment>--format</comment> option:
<info>php app/console help --format=xml list</info>
To display the list of available commands, please use the <info>list</info> command.
### Arguments:
**command_name:**
* Name: command_name
* Is required: no
* Is array: no
* Description: The command name
* Default: `'help'`
### Options:
**xml:**
* Name: `--xml`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output help as XML
* Default: `false`
**format:**
* Name: `--format`
* Shortcut: <none>
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: To output help in other formats
* Default: `NULL`
**raw:**
* Name: `--raw`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output raw command help
* Default: `false`
**help:**
* Name: `--help`
* Shortcut: `-h`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this help message.
* Default: `false`
**quiet:**
* Name: `--quiet`
* Shortcut: `-q`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not output any message.
* Default: `false`
**verbose:**
* Name: `--verbose`
* Shortcut: `-v|-vv|-vvv`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
* Default: `false`
**version:**
* Name: `--version`
* Shortcut: `-V`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this application version.
* Default: `false`
**ansi:**
* Name: `--ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Force ANSI output.
* Default: `false`
**no-ansi:**
* Name: `--no-ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Disable ANSI output.
* Default: `false`
**no-interaction:**
* Name: `--no-interaction`
* Shortcut: `-n`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not ask any interactive question.
* Default: `false`
list
----
* Description: Lists commands
* Usage: `list [--xml] [--raw] [--format="..."] [namespace]`
* Aliases: <none>
The <info>list</info> command lists all commands:
<info>php app/console list</info>
You can also display the commands for a specific namespace:
<info>php app/console list test</info>
You can also output the information in other formats by using the <comment>--format</comment> option:
<info>php app/console list --format=xml</info>
It's also possible to get raw list of commands (useful for embedding command runner):
<info>php app/console list --raw</info>
### Arguments:
**namespace:**
* Name: namespace
* Is required: no
* Is array: no
* Description: The namespace name
* Default: `NULL`
### Options:
**xml:**
* Name: `--xml`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output list as XML
* Default: `false`
**raw:**
* Name: `--raw`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output raw command list
* Default: `false`
**format:**
* Name: `--format`
* Shortcut: <none>
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: To output list in other formats
* Default: `NULL`
descriptor:command1
-------------------
* Description: command 1 description
* Usage: `descriptor:command1`
* Aliases: `alias1`, `alias2`
command 1 help
### Options:
**help:**
* Name: `--help`
* Shortcut: `-h`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this help message.
* Default: `false`
**quiet:**
* Name: `--quiet`
* Shortcut: `-q`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not output any message.
* Default: `false`
**verbose:**
* Name: `--verbose`
* Shortcut: `-v|-vv|-vvv`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
* Default: `false`
**version:**
* Name: `--version`
* Shortcut: `-V`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this application version.
* Default: `false`
**ansi:**
* Name: `--ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Force ANSI output.
* Default: `false`
**no-ansi:**
* Name: `--no-ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Disable ANSI output.
* Default: `false`
**no-interaction:**
* Name: `--no-interaction`
* Shortcut: `-n`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not ask any interactive question.
* Default: `false`
descriptor:command2
-------------------
* Description: command 2 description
* Usage: `descriptor:command2 [-o|--option_name] argument_name`
* Aliases: <none>
command 2 help
### Arguments:
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: <none>
* Default: `NULL`
### Options:
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: <none>
* Default: `false`
**help:**
* Name: `--help`
* Shortcut: `-h`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this help message.
* Default: `false`
**quiet:**
* Name: `--quiet`
* Shortcut: `-q`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not output any message.
* Default: `false`
**verbose:**
* Name: `--verbose`
* Shortcut: `-v|-vv|-vvv`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
* Default: `false`
**version:**
* Name: `--version`
* Shortcut: `-V`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Display this application version.
* Default: `false`
**ansi:**
* Name: `--ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Force ANSI output.
* Default: `false`
**no-ansi:**
* Name: `--no-ansi`
* Shortcut: <none>
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Disable ANSI output.
* Default: `false`
**no-interaction:**
* Name: `--no-interaction`
* Shortcut: `-n`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: Do not ask any interactive question.
* Default: `false`

View File

@@ -0,0 +1,22 @@
<info>My Symfony application</info> version <comment>v1.0</comment>
<comment>Usage:</comment>
[options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
<comment>Available commands:</comment>
<info>alias1 </info> command 1 description
<info>alias2 </info> command 1 description
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<comment>descriptor</comment>
<info>descriptor:command1 </info> command 1 description
<info>descriptor:command2 </info> command 2 description

View File

@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony>
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
&lt;info&gt;php app/console help list&lt;/info&gt;
You can also output the help in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases/>
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
<defaults>
<default>help</default>
</defaults>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output help as XML</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
&lt;info&gt;php app/console list&lt;/info&gt;
You can also display the commands for a specific namespace:
&lt;info&gt;php app/console list test&lt;/info&gt;
You can also output the information in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console list --format=xml&lt;/info&gt;
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output list as XML</description>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
<defaults/>
</option>
</options>
</command>
<command id="descriptor:command1" name="descriptor:command1">
<usage>descriptor:command1</usage>
<description>command 1 description</description>
<help>command 1 help</help>
<aliases>
<alias>alias1</alias>
<alias>alias2</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
<command id="descriptor:command2" name="descriptor:command2">
<usage>descriptor:command2 [-o|--option_name] argument_name</usage>
<description>command 2 description</description>
<help>command 2 help</help>
<aliases/>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--option_name" shortcut="-o" accept_value="0" is_value_required="0" is_multiple="0">
<description></description>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
</commands>
<namespaces>
<namespace id="_global">
<command>alias1</command>
<command>alias2</command>
<command>help</command>
<command>list</command>
</namespace>
<namespace id="descriptor">
<command>descriptor:command1</command>
<command>descriptor:command2</command>
</namespace>
</namespaces>
</symfony>

View File

@@ -0,0 +1,20 @@
<info>Console Tool</info>
<comment>Usage:</comment>
[options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
<comment>Available commands:</comment>
<info>afoobar </info> The foo:bar command
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<comment>foo</comment>
<info>foo:bar </info> The foo:bar command

View File

@@ -0,0 +1,16 @@
<info>Console Tool</info>
<comment>Usage:</comment>
[options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
<comment>Available commands for the "foo" namespace:</comment>
<info>foo:bar </info> The foo:bar command

View File

@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony>
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
&lt;info&gt;php app/console help list&lt;/info&gt;
You can also output the help in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases />
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
<defaults>
<default>help</default>
</defaults>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output help as XML</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
&lt;info&gt;php app/console list&lt;/info&gt;
You can also display the commands for a specific namespace:
&lt;info&gt;php app/console list test&lt;/info&gt;
You can also output the information in other formats by using the &lt;comment&gt;--format&lt;/comment&gt; option:
&lt;info&gt;php app/console list --format=xml&lt;/info&gt;
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output list as XML</description>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list</description>
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
<defaults/>
</option>
</options>
</command>
<command id="foo:bar" name="foo:bar">
<usage>foo:bar</usage>
<description>The foo:bar command</description>
<help/>
<aliases>
<alias>afoobar</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
</commands>
<namespaces>
<namespace id="_global">
<command>afoobar</command>
<command>help</command>
<command>list</command>
</namespace>
<namespace id="foo">
<command>foo:bar</command>
</namespace>
</namespaces>
</symfony>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony>
<commands namespace="foo">
<command id="foo:bar" name="foo:bar">
<usage>foo:bar</usage>
<description>The foo:bar command</description>
<help/>
<aliases>
<alias>afoobar</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>
</commands>
</symfony>

View File

@@ -0,0 +1,13 @@
<info>Console Tool</info>
<comment>Usage:</comment>
[options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.

View File

@@ -0,0 +1,8 @@
[InvalidArgumentException]
Command "foo" is not defined.

View File

@@ -0,0 +1,11 @@
[InvalidArgumentException]
The "--foo" option does not exist.
list [--xml] [--raw] [--format="..."] [namespace]

View File

@@ -0,0 +1,19 @@
[Exception]
Second exception
[Exception]
First exception
foo3:bar

View File

@@ -0,0 +1,9 @@
[InvalidArgumentException]
Command "foo" is not define
d.

View File

@@ -0,0 +1,17 @@
Console Tool
Usage:
[options] command [arguments]
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version -V Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction -n Do not ask any interactive question.
Available commands:
help Displays help for a command
list Lists commands

View File

@@ -0,0 +1,30 @@
Usage:
help [--xml] [--format="..."] [--raw] [command_name]
Arguments:
command The command to execute
command_name The command name (default: "help")
Options:
--xml To output help as XML
--format To output help in other formats
--raw To output raw command help
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
Help:
The help command displays help for a given command:
php app/console help list
You can also output the help in other formats by using the --format option:
php app/console help --format=xml list
To display the list of available commands, please use the list command.

View File

@@ -0,0 +1,28 @@
Usage:
list [--xml] [--raw] [--format="..."] [namespace]
Arguments:
namespace The namespace name
Options:
--xml To output list as XML
--raw To output raw command list
--format To output list in other formats
Help:
The list command lists all commands:
php app/console list
You can also display the commands for a specific namespace:
php app/console list test
You can also output the information in other formats by using the --format option:
php app/console list --format=xml
It's also possible to get raw list of commands (useful for embedding command runner):
php app/console list --raw

View File

@@ -0,0 +1 @@
Console Tool

View File

@@ -0,0 +1 @@
{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}}

View File

@@ -0,0 +1,8 @@
descriptor:command1
-------------------
* Description: command 1 description
* Usage: `descriptor:command1`
* Aliases: `alias1`, `alias2`
command 1 help

View File

@@ -0,0 +1,7 @@
<comment>Usage:</comment>
descriptor:command1
<comment>Aliases:</comment> <info>alias1, alias2</info>
<comment>Help:</comment>
command 1 help

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command1" name="descriptor:command1">
<usage>descriptor:command1</usage>
<description>command 1 description</description>
<help>command 1 help</help>
<aliases>
<alias>alias1</alias>
<alias>alias2</alias>
</aliases>
<arguments/>
<options/>
</command>

View File

@@ -0,0 +1 @@
{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}

View File

@@ -0,0 +1,30 @@
descriptor:command2
-------------------
* Description: command 2 description
* Usage: `descriptor:command2 [-o|--option_name] argument_name`
* Aliases: <none>
command 2 help
### Arguments:
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: <none>
* Default: `NULL`
### Options:
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: <none>
* Default: `false`

View File

@@ -0,0 +1,11 @@
<comment>Usage:</comment>
descriptor:command2 [-o|--option_name] argument_name
<comment>Arguments:</comment>
<info>argument_name </info>
<comment>Options:</comment>
<info>--option_name</info> (-o)
<comment>Help:</comment>
command 2 help

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command2" name="descriptor:command2">
<usage>descriptor:command2 [-o|--option_name] argument_name</usage>
<description>command 2 description</description>
<help>command 2 help</help>
<aliases/>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--option_name" shortcut="-o" accept_value="0" is_value_required="0" is_multiple="0">
<description></description>
</option>
</options>
</command>

View File

@@ -0,0 +1,18 @@
<comment>Usage:</comment>
namespace:name
<comment>Aliases:</comment> <info>name</info>
<comment>Arguments:</comment>
<info>command </info> The command to execute
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message.
<info>--quiet</info> (-q) Do not output any message.
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> (-n) Do not ask any interactive question.
<comment>Help:</comment>
help

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="namespace:name" name="namespace:name">
<usage>namespace:name</usage>
<description>description</description>
<help>help</help>
<aliases>
<alias>name</alias>
</aliases>
<arguments>
<argument name="command" is_required="1" is_array="0">
<description>The command to execute</description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>
</command>

View File

@@ -0,0 +1,11 @@
<comment>Arguments:</comment>
<info>foo </info> The foo argument
<info>baz </info> The baz argument<comment> (default: true)</comment>
<info>bar </info> The bar argument<comment> (default: ["http://foo.com/"])</comment>
<comment>Options:</comment>
<info>--foo</info> (-f) The foo option
<info>--baz</info> The baz option<comment> (default: false)</comment>
<info>--bar</info> (-b) The bar option<comment> (default: "bar")</comment>
<info>--qux</info> The qux option<comment> (default: ["http://foo.com/","bar"])</comment><comment> (multiple values allowed)</comment>
<info>--qux2</info> The qux2 option<comment> (default: {"foo":"bar"})</comment><comment> (multiple values allowed)</comment>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition>
<arguments>
<argument name="foo" is_required="0" is_array="0">
<description>The foo argument</description>
<defaults/>
</argument>
<argument name="baz" is_required="0" is_array="0">
<description>The baz argument</description>
<defaults>
<default>true</default>
</defaults>
</argument>
<argument name="bar" is_required="0" is_array="1">
<description>The bar argument</description>
<defaults>
<default>bar</default>
</defaults>
</argument>
</arguments>
<options>
<option name="--foo" shortcut="-f" accept_value="1" is_value_required="1" is_multiple="0">
<description>The foo option</description>
<defaults/>
</option>
<option name="--baz" shortcut="" accept_value="1" is_value_required="0" is_multiple="0">
<description>The baz option</description>
<defaults>
<default>false</default>
</defaults>
</option>
<option name="--bar" shortcut="-b" accept_value="1" is_value_required="0" is_multiple="0">
<description>The bar option</description>
<defaults>
<default>bar</default>
</defaults>
</option>
</options>
</definition>

View File

@@ -0,0 +1 @@
{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}

View File

@@ -0,0 +1,7 @@
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: <none>
* Default: `NULL`

View File

@@ -0,0 +1 @@
<info>argument_name</info>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>
<defaults/>
</argument>

View File

@@ -0,0 +1 @@
{"name":"argument_name","is_required":false,"is_array":true,"description":"argument description","default":[]}

View File

@@ -0,0 +1,7 @@
**argument_name:**
* Name: argument_name
* Is required: no
* Is array: yes
* Description: argument description
* Default: `array ()`

View File

@@ -0,0 +1 @@
<info>argument_name</info> argument description

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="0" is_array="1">
<description>argument description</description>
<defaults/>
</argument>

View File

@@ -0,0 +1 @@
{"name":"argument_name","is_required":false,"is_array":false,"description":"argument description","default":"default_value"}

View File

@@ -0,0 +1,7 @@
**argument_name:**
* Name: argument_name
* Is required: no
* Is array: no
* Description: argument description
* Default: `'default_value'`

View File

@@ -0,0 +1 @@
<info>argument_name</info> argument description<comment> (default: "default_value")</comment>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="0" is_array="0">
<description>argument description</description>
<defaults>
<default>default_value</default>
</defaults>
</argument>

View File

@@ -0,0 +1 @@
{"arguments":[],"options":[]}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition>
<arguments/>
<options/>
</definition>

View File

@@ -0,0 +1 @@
{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":[]}

View File

@@ -0,0 +1,9 @@
### Arguments:
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: <none>
* Default: `NULL`

View File

@@ -0,0 +1,2 @@
<comment>Arguments:</comment>
<info>argument_name </info>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>
<defaults/>
</argument>
</arguments>
<options/>
</definition>

View File

@@ -0,0 +1 @@
{"arguments":[],"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}

View File

@@ -0,0 +1,11 @@
### Options:
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: <none>
* Default: `false`

View File

@@ -0,0 +1,2 @@
<comment>Options:</comment>
<info>--option_name</info> (-o)

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition>
<arguments/>
<options>
<option name="--option_name" shortcut="-o" accept_value="0" is_value_required="0" is_multiple="0">
<description></description>
</option>
</options>
</definition>

View File

@@ -0,0 +1 @@
{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}

View File

@@ -0,0 +1,21 @@
### Arguments:
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: <none>
* Default: `NULL`
### Options:
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: <none>
* Default: `false`

View File

@@ -0,0 +1,5 @@
<comment>Arguments:</comment>
<info>argument_name </info>
<comment>Options:</comment>
<info>--option_name</info> (-o)

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>
<defaults/>
</argument>
</arguments>
<options>
<option name="--option_name" shortcut="-o" accept_value="0" is_value_required="0" is_multiple="0">
<description></description>
</option>
</options>
</definition>

View File

@@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}

View File

@@ -0,0 +1,9 @@
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: <none>
* Default: `false`

View File

@@ -0,0 +1 @@
<info>--option_name</info> (-o)

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="0" is_value_required="0" is_multiple="0">
<description></description>
</option>

View File

@@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"option description","default":"default_value"}

View File

@@ -0,0 +1,9 @@
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: no
* Is multiple: no
* Description: option description
* Default: `'default_value'`

View File

@@ -0,0 +1 @@
<info>--option_name</info> (-o) option description<comment> (default: "default_value")</comment>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="0" is_multiple="0">
<description>option description</description>
<defaults>
<default>default_value</default>
</defaults>
</option>

View File

@@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"option description","default":null}

View File

@@ -0,0 +1,9 @@
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: option description
* Default: `NULL`

View File

@@ -0,0 +1 @@
<info>--option_name</info> (-o) option description

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
<description>option description</description>
<defaults/>
</option>

View File

@@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":true,"description":"option description","default":[]}

View File

@@ -0,0 +1,9 @@
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: no
* Is multiple: yes
* Description: option description
* Default: `array ()`

View File

@@ -0,0 +1 @@
<info>--option_name</info> (-o) option description<comment> (multiple values allowed)</comment>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="0" is_multiple="1">
<description>option description</description>
<defaults/>
</option>

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Formatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class OutputFormatterStyleStackTest extends \PHPUnit_Framework_TestCase
{
public function testPush()
{
$stack = new OutputFormatterStyleStack();
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
$this->assertEquals($s2, $stack->getCurrent());
$stack->push($s3 = new OutputFormatterStyle('green', 'red'));
$this->assertEquals($s3, $stack->getCurrent());
}
public function testPop()
{
$stack = new OutputFormatterStyleStack();
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
$this->assertEquals($s2, $stack->pop());
$this->assertEquals($s1, $stack->pop());
}
public function testPopEmpty()
{
$stack = new OutputFormatterStyleStack();
$style = new OutputFormatterStyle();
$this->assertEquals($style, $stack->pop());
}
public function testPopNotLast()
{
$stack = new OutputFormatterStyleStack();
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
$stack->push($s3 = new OutputFormatterStyle('green', 'red'));
$this->assertEquals($s2, $stack->pop($s2));
$this->assertEquals($s1, $stack->pop());
}
/**
* @expectedException InvalidArgumentException
*/
public function testInvalidPop()
{
$stack = new OutputFormatterStyleStack();
$stack->push(new OutputFormatterStyle('white', 'black'));
$stack->pop(new OutputFormatterStyle('yellow', 'blue'));
}
}

View File

@@ -0,0 +1,93 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Formatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
$this->assertEquals("\033[32;40;1;4mfoo\033[0m", $style->apply('foo'));
$style = new OutputFormatterStyle('red', null, array('blink'));
$this->assertEquals("\033[31;5mfoo\033[0m", $style->apply('foo'));
$style = new OutputFormatterStyle(null, 'white');
$this->assertEquals("\033[47mfoo\033[0m", $style->apply('foo'));
}
public function testForeground()
{
$style = new OutputFormatterStyle();
$style->setForeground('black');
$this->assertEquals("\033[30mfoo\033[0m", $style->apply('foo'));
$style->setForeground('blue');
$this->assertEquals("\033[34mfoo\033[0m", $style->apply('foo'));
$this->setExpectedException('InvalidArgumentException');
$style->setForeground('undefined-color');
}
public function testBackground()
{
$style = new OutputFormatterStyle();
$style->setBackground('black');
$this->assertEquals("\033[40mfoo\033[0m", $style->apply('foo'));
$style->setBackground('yellow');
$this->assertEquals("\033[43mfoo\033[0m", $style->apply('foo'));
$this->setExpectedException('InvalidArgumentException');
$style->setBackground('undefined-color');
}
public function testOptions()
{
$style = new OutputFormatterStyle();
$style->setOptions(array('reverse', 'conceal'));
$this->assertEquals("\033[7;8mfoo\033[0m", $style->apply('foo'));
$style->setOption('bold');
$this->assertEquals("\033[7;8;1mfoo\033[0m", $style->apply('foo'));
$style->unsetOption('reverse');
$this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
$style->setOption('bold');
$this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
$style->setOptions(array('bold'));
$this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));
try {
$style->setOption('foo');
$this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
}
try {
$style->unsetOption('foo');
$this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
}
}
}

View File

@@ -0,0 +1,231 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Formatter;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class FormatterStyleTest extends \PHPUnit_Framework_TestCase
{
public function testEmptyTag()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("foo<>bar", $formatter->format('foo<>bar'));
}
public function testLGCharEscaping()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("foo<bar", $formatter->format('foo\\<bar'));
$this->assertEquals("<info>some info</info>", $formatter->format('\\<info>some info\\</info>'));
$this->assertEquals("\\<info>some info\\</info>", OutputFormatter::escape('<info>some info</info>'));
$this->assertEquals(
"\033[33mSymfony\\Component\\Console does work very well!\033[0m",
$formatter->format('<comment>Symfony\Component\Console does work very well!</comment>')
);
}
public function testBundledStyles()
{
$formatter = new OutputFormatter(true);
$this->assertTrue($formatter->hasStyle('error'));
$this->assertTrue($formatter->hasStyle('info'));
$this->assertTrue($formatter->hasStyle('comment'));
$this->assertTrue($formatter->hasStyle('question'));
$this->assertEquals(
"\033[37;41msome error\033[0m",
$formatter->format('<error>some error</error>')
);
$this->assertEquals(
"\033[32msome info\033[0m",
$formatter->format('<info>some info</info>')
);
$this->assertEquals(
"\033[33msome comment\033[0m",
$formatter->format('<comment>some comment</comment>')
);
$this->assertEquals(
"\033[30;46msome question\033[0m",
$formatter->format('<question>some question</question>')
);
}
public function testNestedStyles()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"\033[37;41msome \033[0m\033[32msome info\033[0m\033[37;41m error\033[0m",
$formatter->format('<error>some <info>some info</info> error</error>')
);
}
public function testStyleMatchingNotGreedy()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"(\033[32m>=2.0,<2.3\033[0m)",
$formatter->format('(<info>>=2.0,<2.3</info>)')
);
}
public function testStyleEscaping()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"(\033[32mz>=2.0,<a2.3\033[0m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
);
}
public function testDeepNestedStyles()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"\033[37;41merror\033[0m\033[32minfo\033[0m\033[33mcomment\033[0m\033[37;41merror\033[0m",
$formatter->format('<error>error<info>info<comment>comment</info>error</error>')
);
}
public function testNewStyle()
{
$formatter = new OutputFormatter(true);
$style = new OutputFormatterStyle('blue', 'white');
$formatter->setStyle('test', $style);
$this->assertEquals($style, $formatter->getStyle('test'));
$this->assertNotEquals($style, $formatter->getStyle('info'));
$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<test>some custom msg</test>'));
}
public function testRedefineStyle()
{
$formatter = new OutputFormatter(true);
$style = new OutputFormatterStyle('blue', 'white');
$formatter->setStyle('info', $style);
$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<info>some custom msg</info>'));
}
public function testInlineStyle()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('<fg=blue;bg=red>some text</>'));
$this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('<fg=blue;bg=red>some text</fg=blue;bg=red>'));
}
public function testNonStyleTag()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled\033[0m", $formatter->format('<info>some <tag> styled</info>'));
}
public function testNotDecoratedFormatter()
{
$formatter = new OutputFormatter(false);
$this->assertTrue($formatter->hasStyle('error'));
$this->assertTrue($formatter->hasStyle('info'));
$this->assertTrue($formatter->hasStyle('comment'));
$this->assertTrue($formatter->hasStyle('question'));
$this->assertEquals(
"some error", $formatter->format('<error>some error</error>')
);
$this->assertEquals(
"some info", $formatter->format('<info>some info</info>')
);
$this->assertEquals(
"some comment", $formatter->format('<comment>some comment</comment>')
);
$this->assertEquals(
"some question", $formatter->format('<question>some question</question>')
);
$formatter->setDecorated(true);
$this->assertEquals(
"\033[37;41msome error\033[0m", $formatter->format('<error>some error</error>')
);
$this->assertEquals(
"\033[32msome info\033[0m", $formatter->format('<info>some info</info>')
);
$this->assertEquals(
"\033[33msome comment\033[0m", $formatter->format('<comment>some comment</comment>')
);
$this->assertEquals(
"\033[30;46msome question\033[0m", $formatter->format('<question>some question</question>')
);
}
public function testContentWithLineBreaks()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(<<<EOF
\033[32m
some text\033[0m
EOF
, $formatter->format(<<<EOF
<info>
some text</info>
EOF
));
$this->assertEquals(<<<EOF
\033[32msome text
\033[0m
EOF
, $formatter->format(<<<EOF
<info>some text
</info>
EOF
));
$this->assertEquals(<<<EOF
\033[32m
some text
\033[0m
EOF
, $formatter->format(<<<EOF
<info>
some text
</info>
EOF
));
$this->assertEquals(<<<EOF
\033[32m
some text
more text
\033[0m
EOF
, $formatter->format(<<<EOF
<info>
some text
more text
</info>
EOF
));
}
}

Some files were not shown because too many files have changed in this diff Show More