ListCommandTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tests\Command;
  11. use Symfony\Component\Console\Tester\CommandTester;
  12. use Symfony\Component\Console\Application;
  13. class ListCommandTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testExecuteListsCommands()
  16. {
  17. $application = new Application();
  18. $commandTester = new CommandTester($command = $application->get('list'));
  19. $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
  20. $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
  21. }
  22. public function testExecuteListsCommandsWithXmlOption()
  23. {
  24. $application = new Application();
  25. $commandTester = new CommandTester($command = $application->get('list'));
  26. $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
  27. $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
  28. }
  29. public function testExecuteListsCommandsWithRawOption()
  30. {
  31. $application = new Application();
  32. $commandTester = new CommandTester($command = $application->get('list'));
  33. $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
  34. $output = <<<'EOF'
  35. help Displays help for a command
  36. list Lists commands
  37. EOF;
  38. $this->assertEquals($output, $commandTester->getDisplay(true));
  39. }
  40. public function testExecuteListsCommandsWithNamespaceArgument()
  41. {
  42. require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
  43. $application = new Application();
  44. $application->add(new \FooCommand());
  45. $commandTester = new CommandTester($command = $application->get('list'));
  46. $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
  47. $output = <<<'EOF'
  48. foo:bar The foo:bar command
  49. EOF;
  50. $this->assertEquals($output, $commandTester->getDisplay(true));
  51. }
  52. public function testExecuteListsCommandsOrder()
  53. {
  54. require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
  55. $application = new Application();
  56. $application->add(new \Foo6Command());
  57. $commandTester = new CommandTester($command = $application->get('list'));
  58. $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
  59. $output = <<<'EOF'
  60. Console Tool
  61. Usage:
  62. command [options] [arguments]
  63. Options:
  64. -h, --help Display this help message
  65. -q, --quiet Do not output any message
  66. -V, --version Display this application version
  67. --ansi Force ANSI output
  68. --no-ansi Disable ANSI output
  69. -n, --no-interaction Do not ask any interactive question
  70. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  71. Available commands:
  72. help Displays help for a command
  73. list Lists commands
  74. 0foo
  75. 0foo:bar 0foo:bar command
  76. EOF;
  77. $this->assertEquals($output, trim($commandTester->getDisplay(true)));
  78. }
  79. public function testExecuteListsCommandsOrderRaw()
  80. {
  81. require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
  82. $application = new Application();
  83. $application->add(new \Foo6Command());
  84. $commandTester = new CommandTester($command = $application->get('list'));
  85. $commandTester->execute(array('command' => $command->getName(), '--raw' => true));
  86. $output = <<<'EOF'
  87. help Displays help for a command
  88. list Lists commands
  89. 0foo:bar 0foo:bar command
  90. EOF;
  91. $this->assertEquals($output, trim($commandTester->getDisplay(true)));
  92. }
  93. }