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/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/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..99784754d6 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -12,12 +12,12 @@ 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\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 { @@ -32,11 +32,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'); @@ -68,7 +80,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() @@ -279,7 +291,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 { @@ -295,14 +307,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'); } @@ -314,18 +328,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->assertRegExp('/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'); } @@ -341,82 +355,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'); $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', $this->normalize($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->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalize($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->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalize($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'); - $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->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->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalize($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'); - $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->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->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalize($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'); - $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/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();