From 304e13daa329b2e10f672721f0cbf9d860bb06c0 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 12 Feb 2012 16:37:55 +0100 Subject: [PATCH 1/3] replaced command names with supported placeholders in help texts --- .../Command/AssetsInstallCommand.php | 10 +-- .../Command/CacheClearCommand.php | 6 +- .../Command/CacheWarmupCommand.php | 2 +- .../Command/ConfigDumpReferenceCommand.php | 11 ++-- .../Command/ContainerDebugCommand.php | 10 +-- .../Command/RouterApacheDumperCommand.php | 6 +- .../Command/RouterDebugCommand.php | 6 +- .../Command/RouterMatchCommand.php | 6 +- .../Command/TranslationUpdateCommand.php | 11 ++-- .../SecurityBundle/Command/InitAclCommand.php | 11 ++-- .../Component/Console/Command/HelpCommand.php | 11 ++-- .../Component/Console/Command/ListCommand.php | 15 ++--- .../Component/Console/Output/Output.php | 6 +- .../Console/Tester/ApplicationTester.php | 2 + .../Component/Console/ApplicationTest.php | 63 +++++++------------ .../Console/Fixtures/application_asxml1.txt | 16 ++--- .../Console/Fixtures/application_run1.txt | 17 ----- .../Console/Fixtures/application_run2.txt | 26 -------- .../Console/Fixtures/application_run3.txt | 27 -------- .../Console/Fixtures/application_run4.txt | 1 - 20 files changed, 89 insertions(+), 174 deletions(-) delete mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt delete mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt delete mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt delete mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index fd756a2f71..bc145a241a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -31,6 +31,7 @@ class AssetsInstallCommand extends ContainerAwareCommand protected function configure() { $this + ->setName('assets:install') ->setDefinition(array( new InputArgument('target', InputArgument::REQUIRED, 'The target directory (usually "web")'), )) @@ -38,10 +39,10 @@ class AssetsInstallCommand extends ContainerAwareCommand ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') ->setDescription('Installs bundles web assets under a public web directory') ->setHelp(<<assets:install command installs bundle assets into a given +The %command.name% command installs bundle assets into a given directory (e.g. the web directory). -php app/console assets:install web +php %command.full_name% web A "bundles" directory will be created inside the target directory, and the "Resources/public" directory of each bundle will be copied into it. @@ -49,15 +50,14 @@ A "bundles" directory will be created inside the target directory, and the To create a symlink to each bundle instead of copying its assets, use the --symlink option: -php app/console assets:install web --symlink +php %command.full_name% web --symlink To make symlink relative, add the --relative option: -php app/console assets:install web --symlink --relative +php %command.full_name% web --symlink --relative EOT ) - ->setName('assets:install') ; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index fdce7084f2..a9aa7a5b8f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -40,11 +40,11 @@ class CacheClearCommand extends ContainerAwareCommand )) ->setDescription('Clears the cache') ->setHelp(<<cache:clear command clears the application cache for a given environment +The %command.name% command clears the application cache for a given environment and debug mode: -php app/console cache:clear --env=dev -php app/console cache:clear --env=prod --no-debug +php %command.full_name% --env=dev +php %command.full_name% --env=prod --no-debug EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index 1c2ba0e790..e997e55df7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -34,7 +34,7 @@ class CacheWarmupCommand extends ContainerAwareCommand )) ->setDescription('Warms up an empty cache') ->setHelp(<<cache:warmup command warms up the cache. +The %command.name% command warms up the cache. Before running this command, the cache must be empty. EOF diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index 30a870df75..3886c91260 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -33,24 +33,23 @@ class ConfigDumpReferenceCommand extends ContainerDebugCommand protected function configure() { $this + ->setName('config:dump-reference') ->setDefinition(array( new InputArgument('name', InputArgument::REQUIRED, 'The Bundle or extension alias') )) - ->setName('config:dump-reference') - ->setDescription('Dumps default configuration for an extension.') + ->setDescription('Dumps default configuration for an extension') ->setHelp(<<config:dump-reference command dumps the default configuration for an extension/bundle. +The %command.name% command dumps the default configuration for an extension/bundle. The extension alias or bundle name can be used: Example: - %command.name% framework + php %command.full_name% framework or - %command.name% FrameworkBundle - + php %command.full_name% FrameworkBundle EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 2229848965..dcfe53aa7a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -40,25 +40,25 @@ class ContainerDebugCommand extends ContainerAwareCommand protected function configure() { $this + ->setName('container:debug') ->setDefinition(array( new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'), new InputOption('show-private', null, InputOption::VALUE_NONE, 'Use to show public *and* private services'), )) - ->setName('container:debug') ->setDescription('Displays current services for an application') ->setHelp(<<container:debug command displays all configured public services: +The %command.name% command displays all configured public services: - container:debug + php %command.full_name% To get specific information about a service, specify its name: - container:debug validator + php %command.full_name% validator By default, private services are hidden. You can display all services by using the --show-private flag: - container:debug --show-private + php %command.full_name% --show-private EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php index c19699c8b9..12fe9b028e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php @@ -47,18 +47,18 @@ class RouterApacheDumperCommand extends ContainerAwareCommand protected function configure() { $this + ->setName('router:dump-apache') ->setDefinition(array( new InputArgument('script_name', InputArgument::OPTIONAL, 'The script name of the application\'s front controller.'), new InputOption('base-uri', null, InputOption::VALUE_REQUIRED, 'The base URI'), )) - ->setName('router:dump-apache') ->setDescription('Dumps all routes as Apache rewrite rules') ->setHelp(<<router:dump-apache dumps all routes as Apache rewrite rules. +The %command.name% dumps all routes as Apache rewrite rules. These can then be used with the ApacheUrlMatcher to use Apache for route matching. - router:dump-apache + php %command.full_name% EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 482f0ad763..01be52a02a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -46,15 +46,15 @@ class RouterDebugCommand extends ContainerAwareCommand protected function configure() { $this + ->setName('router:debug') ->setDefinition(array( new InputArgument('name', InputArgument::OPTIONAL, 'A route name'), )) - ->setName('router:debug') ->setDescription('Displays current routes for an application') ->setHelp(<<router:debug displays the configured routes: +The %command.name% displays the configured routes: - router:debug + php %command.full_name% EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php index 5207ee7bd0..a6b4b08556 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php @@ -46,15 +46,15 @@ class RouterMatchCommand extends ContainerAwareCommand protected function configure() { $this + ->setName('router:match') ->setDefinition(array( new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'), )) - ->setName('router:match') ->setDescription('Helps debug routes by simulating a path info match') ->setHelp(<<router:match simulates a path info match: +The %command.name% simulates a path info match: - router:match /foo + php %command.full_name% /foo EOF ) ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 4997738dba..0d7a56c2be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -40,7 +40,6 @@ class TranslationUpdateCommand extends ContainerAwareCommand { $this ->setName('translation:update') - ->setDescription('Update the translation file') ->setDefinition(array( new InputArgument('locale', InputArgument::REQUIRED, 'The locale'), new InputArgument('bundle', InputArgument::REQUIRED, 'The bundle where to load the messages'), @@ -61,16 +60,18 @@ class TranslationUpdateCommand extends ContainerAwareCommand 'Should the update be done' ) )) + ->setDescription('Update the translation file') ->setHelp(<<translation:update command extract translation strings from templates +The %command.name% command extract translation strings from templates of a given bundle. It can display them or merge the new ones into the translation files. When new translation strings are found it can automatically add a prefix to the translation message. -php app/console translation:update --dump-messages en AcmeBundle -php app/console translation:update --force --prefix="new_" fr AcmeBundle +php %command.full_name% --dump-messages en AcmeBundle +php %command.full_name% --force --prefix="new_" fr AcmeBundle EOF - ); + ) + ; } /** diff --git a/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php b/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php index b717f97c86..eaa518f97b 100644 --- a/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php +++ b/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php @@ -32,18 +32,19 @@ class InitAclCommand extends ContainerAwareCommand $this ->setName('init:acl') ->setDescription('Mounts ACL tables in the database') - ->setHelp(<<init:acl command mounts ACL tables in the database. + ->setHelp(<<%command.name% command mounts ACL tables in the database. -php app/console init:acl +php %command.full_name% The name of the DBAL connection must be configured in your app/config/security.yml configuration file in the security.acl.connection variable. security: acl: connection: default -EOT - ); +EOF + ) + ; } /** diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 9b4256899b..93c81045c7 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -35,22 +35,23 @@ class HelpCommand extends Command $this->ignoreValidationErrors(); $this + ->setName('help') ->setDefinition(array( new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'), )) - ->setName('help') ->setDescription('Displays help for a command') ->setHelp(<<help command displays help for a given command: +The %command.name% command displays help for a given command: - php app/console help list + php %command.full_name% list You can also output the help as XML by using the --xml option: - php app/console help --xml list + php %command.full_name% --xml list EOF - ); + ) + ; } /** diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 14f6f430d1..032de16c1c 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -32,27 +32,28 @@ class ListCommand extends Command protected function configure() { $this - ->setDefinition($this->createDefinition()) ->setName('list') + ->setDefinition($this->createDefinition()) ->setDescription('Lists commands') ->setHelp(<<list command lists all commands: +The %command.name% command lists all commands: - php app/console list + php %command.full_name% You can also display the commands for a specific namespace: - php app/console list test + php %command.full_name% test You can also output the information as XML by using the --xml option: - php app/console list --xml + php %command.full_name% --xml It's also possible to get raw list of commands (useful for embedding command runner): - php app/console list --raw + php %command.full_name% --raw EOF - ); + ) + ; } /** diff --git a/src/Symfony/Component/Console/Output/Output.php b/src/Symfony/Component/Console/Output/Output.php index 4e3ffa1ab1..2227880160 100644 --- a/src/Symfony/Component/Console/Output/Output.php +++ b/src/Symfony/Component/Console/Output/Output.php @@ -43,12 +43,8 @@ abstract class Output implements OutputInterface */ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) { - if (null === $formatter) { - $formatter = new OutputFormatter(); - } - $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity; - $this->formatter = $formatter; + $this->formatter = null === $formatter ? new OutputFormatter() : $formatter; $this->formatter->setDecorated((Boolean) $decorated); } diff --git a/src/Symfony/Component/Console/Tester/ApplicationTester.php b/src/Symfony/Component/Console/Tester/ApplicationTester.php index e3093cade2..9412fbabfc 100644 --- a/src/Symfony/Component/Console/Tester/ApplicationTester.php +++ b/src/Symfony/Component/Console/Tester/ApplicationTester.php @@ -13,6 +13,8 @@ namespace Symfony\Component\Console\Tester; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; /** diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index 4e4e2fa59f..c413108e10 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -12,12 +12,13 @@ namespace Symfony\Tests\Component\Console; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Output\Output; -use Symfony\Component\Console\Tester\ApplicationTester; +use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Console\Output\Output; +use Symfony\Component\Console\Tester\ApplicationTester; class ApplicationTest extends \PHPUnit_Framework_TestCase { @@ -317,7 +318,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exception'); $tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE)); - $this->assertRegExp('/Exception trace/', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose'); + $this->assertContains('Exception trace', $this->normalize($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', $this->normalize($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command'); @@ -341,82 +342,66 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $application->run(); ob_end_clean(); - $this->assertEquals('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given'); - $this->assertEquals('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given'); + $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'); + + $formatter = new OutputFormatter(false); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); + $tester->run(array(), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalize($tester->getDisplay()), '->run() runs the list command if no argument is passed'); + $this->assertSame($formatter->format($application->asText()).PHP_EOL, $tester->getDisplay(), '->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', $this->normalize($tester->getDisplay()), '->run() runs the help command if --help is passed'); + $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if --help is passed'); $tester->run(array('-h' => true), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalize($tester->getDisplay()), '->run() runs the help command if -h is passed'); + $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if -h is passed'); - $application = new Application(); - $application->setAutoExit(false); - $application->setCatchExceptions(false); - $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalize($tester->getDisplay()), '->run() displays the help if --help is passed'); + $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->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', $this->normalize($tester->getDisplay()), '->run() displays the help if -h is passed'); + $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->run() displays the help if -h is passed'); - $application = new Application(); - $application->setAutoExit(false); - $application->setCatchExceptions(false); - $tester = new ApplicationTester($application); $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'); - $application = new Application(); - $application->setAutoExit(false); - $application->setCatchExceptions(false); - $tester = new ApplicationTester($application); $tester->run(array('--version' => true), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalize($tester->getDisplay()), '->run() displays the program version if --version is passed'); + $this->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if --version is passed'); $tester->run(array('-V' => true), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalize($tester->getDisplay()), '->run() displays the program version if -v is passed'); + $this->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if -V is passed'); - $application = new Application(); - $application->setAutoExit(false); - $application->setCatchExceptions(false); - $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--quiet' => true)); - $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if --quiet is passed'); + $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed'); $tester->run(array('command' => 'list', '-q' => true)); - $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if -q is passed'); + $this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed'); - $application = new Application(); - $application->setAutoExit(false); - $application->setCatchExceptions(false); - $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--verbose' => true)); - $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is --verbose is passed'); + $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed'); $tester->run(array('command' => 'list', '-v' => true)); - $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is -v is passed'); + $this->assertSame(Output::VERBOSITY_VERBOSE, $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->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if --no-interaction is passed'); + $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->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if -n is passed'); + $this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed'); } /** diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt index ce21a32869..3ae1fca142 100644 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt @@ -4,13 +4,13 @@ help [--xml] [command_name] Displays help for a command - The <info>help</info> command displays help for a given command: + The <info>%command.name%</info> command displays help for a given command: - <info>php app/console help list</info> + <info>php %command.full_name% list</info> You can also output the help as XML by using the <comment>--xml</comment> option: - <info>php app/console help --xml list</info> + <info>php %command.full_name% --xml list</info> @@ -29,21 +29,21 @@ list [--xml] [--raw] [namespace] Lists commands - The <info>list</info> command lists all commands: + The <info>%command.name%</info> command lists all commands: - <info>php app/console list</info> + <info>php %command.full_name%</info> You can also display the commands for a specific namespace: - <info>php app/console list test</info> + <info>php %command.full_name% test</info> You can also output the information as XML by using the <comment>--xml</comment> option: - <info>php app/console list --xml</info> + <info>php %command.full_name% --xml</info> It's also possible to get raw list of commands (useful for embedding command runner): - <info>php app/console list --raw</info> + <info>php %command.full_name% --raw</info> diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt deleted file mode 100644 index 176dc88101..0000000000 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt +++ /dev/null @@ -1,17 +0,0 @@ -Console Tool - -Usage: - [options] command [arguments] - -Options: - --help -h Display this help message. - --quiet -q Do not output any message. - --verbose -v Increase verbosity of messages. - --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 diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt deleted file mode 100644 index f717033ad3..0000000000 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt +++ /dev/null @@ -1,26 +0,0 @@ -Usage: - help [--xml] [command_name] - -Arguments: - command The command to execute - command_name The command name (default: 'help') - -Options: - --xml To output help as XML - --help (-h) Display this help message. - --quiet (-q) Do not output any message. - --verbose (-v) Increase verbosity of messages. - --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 as XML by using the --xml option: - - php app/console help --xml list - diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt deleted file mode 100644 index 441db54857..0000000000 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt +++ /dev/null @@ -1,27 +0,0 @@ -Usage: - list [--xml] [--raw] [namespace] - -Arguments: - namespace The namespace name - -Options: - --xml To output help as XML - --raw To output raw command list - -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 as XML by using the --xml option: - - php app/console list --xml - - It's also possible to get raw list of commands (useful for embedding command runner): - - php app/console list --raw - diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt deleted file mode 100644 index 47187fc267..0000000000 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt +++ /dev/null @@ -1 +0,0 @@ -Console Tool From 11585c3b67ab48491f83a7949553541e2d4775b2 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 17 Feb 2012 18:58:01 +0100 Subject: [PATCH 2/3] fix Command:asXml to use processed help --- .../Component/Console/Command/Command.php | 7 ++-- .../Component/Console/ApplicationTest.php | 32 +++++++++++++------ .../Component/Console/Command/CommandTest.php | 8 +++++ .../Console/Fixtures/application_asxml1.txt | 16 +++++----- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 010abb433a..033a95c763 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -560,7 +560,7 @@ class Command if ($help = $this->getProcessedHelp()) { $messages[] = 'Help:'; - $messages[] = ' '.implode("\n ", explode("\n", $help))."\n"; + $messages[] = ' '.str_replace("\n", "\n ", $help)."\n"; } return implode("\n", $messages); @@ -585,11 +585,10 @@ class Command $usageXML->appendChild($dom->createTextNode(sprintf($this->getSynopsis(), ''))); $commandXML->appendChild($descriptionXML = $dom->createElement('description')); - $descriptionXML->appendChild($dom->createTextNode(implode("\n ", explode("\n", $this->getDescription())))); + $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getDescription()))); $commandXML->appendChild($helpXML = $dom->createElement('help')); - $help = $this->help; - $helpXML->appendChild($dom->createTextNode(implode("\n ", explode("\n", $help)))); + $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getProcessedHelp()))); $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); foreach ($this->getAliases() as $alias) { diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index c413108e10..f3e5a51e63 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -33,11 +33,23 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase require_once self::$fixturesPath.'/Foo3Command.php'; } - protected function normalize($text) + 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'); @@ -69,7 +81,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase public function testHelp() { $application = new Application(); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', str_replace(PHP_EOL, "\n", $application->getHelp()), '->setHelp() returns a help message'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->setHelp() returns a help message'); } public function testAll() @@ -280,7 +292,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $application->setCatchExceptions(true); $tester->run(array('command' => 'foo'), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalize($tester->getDisplay()), '->setCatchExceptions() sets the catch exception flag'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->setCatchExceptions() sets the catch exception flag'); $application->setCatchExceptions(false); try { @@ -296,14 +308,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase { $application = new Application(); $application->add(new \FooCommand); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', str_replace(PHP_EOL, "\n", $application->asText()), '->asText() returns a text representation of the application'); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', str_replace(PHP_EOL, "\n", $application->asText('foo')), '->asText() returns a text representation of the application'); + $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'); } @@ -315,18 +329,18 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo'), array('decorated' => false)); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exception'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exception'); $tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE)); - $this->assertContains('Exception trace', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exception with a stack trace when verbosity is 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', $this->normalize($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->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', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions'); } diff --git a/tests/Symfony/Tests/Component/Console/Command/CommandTest.php b/tests/Symfony/Tests/Component/Console/Command/CommandTest.php index 81371c019f..0c3f71f4a7 100644 --- a/tests/Symfony/Tests/Component/Console/Command/CommandTest.php +++ b/tests/Symfony/Tests/Component/Console/Command/CommandTest.php @@ -128,6 +128,14 @@ class CommandTest extends \PHPUnit_Framework_TestCase $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(); diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt index 3ae1fca142..ce21a32869 100644 --- a/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt @@ -4,13 +4,13 @@ help [--xml] [command_name] Displays help for a command - The <info>%command.name%</info> command displays help for a given command: + The <info>help</info> command displays help for a given command: - <info>php %command.full_name% list</info> + <info>php app/console help list</info> You can also output the help as XML by using the <comment>--xml</comment> option: - <info>php %command.full_name% --xml list</info> + <info>php app/console help --xml list</info> @@ -29,21 +29,21 @@ list [--xml] [--raw] [namespace] Lists commands - The <info>%command.name%</info> command lists all commands: + The <info>list</info> command lists all commands: - <info>php %command.full_name%</info> + <info>php app/console list</info> You can also display the commands for a specific namespace: - <info>php %command.full_name% test</info> + <info>php app/console list test</info> You can also output the information as XML by using the <comment>--xml</comment> option: - <info>php %command.full_name% --xml</info> + <info>php app/console list --xml</info> It's also possible to get raw list of commands (useful for embedding command runner): - <info>php %command.full_name% --raw</info> + <info>php app/console list --raw</info> From 447d46814c72c20d071a53dbdeb46c9f01262c67 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 21 Mar 2012 05:15:35 +0100 Subject: [PATCH 3/3] restore previous testing style with static fixtures for console --- .../Component/Console/ApplicationTest.php | 19 +++++++------ .../Console/Fixtures/application_run1.txt | 17 ++++++++++++ .../Console/Fixtures/application_run2.txt | 26 ++++++++++++++++++ .../Console/Fixtures/application_run3.txt | 27 +++++++++++++++++++ .../Console/Fixtures/application_run4.txt | 1 + 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index f3e5a51e63..99784754d6 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -12,7 +12,6 @@ namespace Symfony\Tests\Component\Console; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -359,27 +358,27 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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'); - $formatter = new OutputFormatter(false); - $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); + + $this->ensureStaticCommandHelp($application); $tester = new ApplicationTester($application); $tester->run(array(), array('decorated' => false)); - $this->assertSame($formatter->format($application->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the list command if no argument is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the list command if no argument is passed'); $tester->run(array('--help' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if --help is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if --help is passed'); $tester->run(array('-h' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if -h is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if -h is passed'); $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->run() displays the help if --help is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if --help is passed'); $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->run() displays the help if -h is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->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'); @@ -388,10 +387,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if --version is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if --version is passed'); $tester->run(array('-V' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if -V is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->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'); diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt new file mode 100644 index 0000000000..176dc88101 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt @@ -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 Increase verbosity of messages. + --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 diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt new file mode 100644 index 0000000000..f717033ad3 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt @@ -0,0 +1,26 @@ +Usage: + help [--xml] [command_name] + +Arguments: + command The command to execute + command_name The command name (default: 'help') + +Options: + --xml To output help as XML + --help (-h) Display this help message. + --quiet (-q) Do not output any message. + --verbose (-v) Increase verbosity of messages. + --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 as XML by using the --xml option: + + php app/console help --xml list + diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt new file mode 100644 index 0000000000..441db54857 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt @@ -0,0 +1,27 @@ +Usage: + list [--xml] [--raw] [namespace] + +Arguments: + namespace The namespace name + +Options: + --xml To output help as XML + --raw To output raw command list + +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 as XML by using the --xml option: + + php app/console list --xml + + It's also possible to get raw list of commands (useful for embedding command runner): + + php app/console list --raw + diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt new file mode 100644 index 0000000000..47187fc267 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt @@ -0,0 +1 @@ +Console Tool